How to make a tree plot in caret package?

Jot eN picture Jot eN · Jun 3, 2014 · Viewed 26.8k times · Source

I'm using caret package to model the data using rpart package.

library('caret')
data(iris)
formula <- as.formula(Species ~.)
t <- train(formula,iris,method = "rpart",cp=0.002,maxdepth=8)
plot(t)

As a result I get object 't' and I'm trying to plot this object to get tree plot. But the result look like that: enter image description here

Are there any way to make a tree plot from caret train object?

Answer

Jot eN picture Jot eN · Jul 25, 2014

nicer looking treeplot:

library(rattle)
fancyRpartPlot(t$finalModel)

enter image description here