Search code examples
plotcharacterrpartparty

Re-structure the split labels at the end of each leaf in rpart


I am currently working with rpart.plot() to plot a decision tree (like the one attached in the picture).

My concern is whether I can split the line, containing the levels of the decision choice below each leaf, in two lines? In this way the information will be contained in a more reduced space and information will be more visual when I include it in the paper.

One possibility I have tried is to reduce the names forming the levels, but still it does not reduce the dimensionality that much.

In the following figure I represent what I am looking for.

enter image description here

Any clue?

Thank you


Solution

  • Hidden in the vignette for rpart.plot there is an example for this.

    In that vignette, Section 6.1 Customizing the split labels explains how to break up long labels.

    It gives example code and plots. (The example there uses prp, but you can use prp or rpart.plot.)