Search code examples
rplotdecision-treerpart

rpart change text size in node


I would like to change the text size of a node in rpart. The text does not fit into the box of the node if the text is too large. Still, there should be enough space.

rpart.plot(pruned_tree_model, type=0,tweak=1.5,leaf.round=0) 

are there some arguments to add?


Solution

  • you can actually change text size in nodes the same way you control text size in normal plot --- via the cex parameter:

    library(rpart)
    fit <- rpart(Mileage ~ Weight, car.test.frame)
    
    par(mfrow = c(1, 2))
    plot(fit)
    text(fit)
    plot(fit)
    text(fit, cex = 0.5)
    

    enter image description here