Graphic tree in ggplot in R

I wonder if it is possible to build a ggplot tree? let's say:

library(rpart
library(rpart.plot)

data(iris)
mod <- rpart(Species~., data=iris)
prp(mod)

enter image description here

Is it possible to build a similar graph in ggplot?

+4
source share
1 answer

The feature autoplot.rpart()in the package survMisccan help you with this. But you will probably need to clear the presentation of the plot, potentially stratification in characters, etc. This seems to be just the starting point:

library(rpart)
library(survMisc)

data(iris)
mod <- rpart(Species~., data=iris)

autoplot(mod, branch=0)

ggplot2 rpart fit

+4
source

All Articles