How to plot a sample tree from random forest in R




I am using randomForest for a classification problem.I am interested in seeing the plot of a single tree from the forest so that I get an idea of the splits being done.Is there any function in the randomForest package or otherwise in R to achieve the same.


The randomForest package doesn’t have any in-built way for plotting the trees. You can use the ‘party’ package. It has the required plotting function inbuilt in the package.

Package ‘party’ sample code:

x <- ctree(Species ~ ., data=iris)
plot(x, type="simple")

It gave the following image as output:

Of course, you can choose to write the function that converts the randomForest output to a tree.