Labels are blank in Decision Tree plot in r

I am using caret package to train my model.

My model is working fine. But when I plot the decision tree, the labels are blank. How do i get the labels?

carMod <- train( FLAG ~.,data=df_train, method="rpart" )
plot(carMod$finalModel)

enter image description here

Upvotes: 3

Views: 3528

Answers (2)

Stephen Milborrow
Stephen Milborrow

Reputation: 1016

Use the following code, as explained on the help page for plot.rpart (https://stat.ethz.ch/R-manual/R-devel/library/rpart/html/plot.rpart.html):

plot(carMod$finalModel)
text(carMod$finalModel)

Alternatively use

library(rpart.plot)
rpart.plot(carMod$finalModel)

For more information, see https://blog.revolutionanalytics.com/2013/06/plotting-classification-and-regression-trees-with-plotrpart.html

Upvotes: 0

Julius Vainora
Julius Vainora

Reputation: 48211

You need

plot(carMod$finalModel)
text(carMod$finalModel)

Upvotes: 5

Related Questions