2) Visualise a rpart Decision Tree

This Blog entry is from the Probability and Trees section in Learn R.

Once familiar with the output of a regression tree, it becomes an informative means to create business rules. Quite often however, for the purposes of communication, it is more satisfying to create a visualisation.  A package called rpart.plot is available for the purposes of translating regression trees to a visualisation.  Start by installing the rpart.plot package:

1.png

Click install to download and install the package:

2.png

Reference the library:

library(rpart.plot)
3.png

Run the line of script to console:

4.png

To transpose the Regression Tree to a plot, simply pass it as an argument to the rpart.plot() function:

rpart.plot(RegressionTree)
5.png

Run the line of script to console:

6.png

It can be seen that a complex visualisation has been created in the plots window of R Studio:

7.png

The visualisation is exceptionally hard to interpret for a large regression tree; hence it will likely need to be exported to a PDF or Image file to use a zoom function:

8.png