data("cu.summary", package="rpart")
fit <- rpart::rpart(Price ~ Mileage + Type + Country, cu.summary)
autoplot(fit)
data("stagec", package="rpart")
progstat <- factor(stagec$pgstat, levels = 0:1, labels = c("No", "Prog"))
cfit <- rpart::rpart(progstat ~ age + eet + g2 + grade + gleason + ploidy,
data = stagec, method = 'class')
autoplot(cfit)
set.seed(1)
df1 <- genSurvDf(model=FALSE)
r1 <- rpart::rpart(Surv(t1, e) ~ ., data=df1, method="exp")
autoplot(r1, leaf="en", title="Nodes show events / no. at risk")
autoplot(r1, compress=TRUE, branch=0.5, nspace=0.1,
title="Nodes show events / no. at risk")
### oversize text; need to adjust 'y' values for text to compensate
a1 <- autoplot(r1, compress=TRUE, digits=5,
nodeSize=10, yNU=0.05, yND=0.03,
leafSize=10, , yLD=0.08, nodeLabels=seq(17))$plot
### can use expand_limits if text is cut off at margins
a1 + ggplot2::expand_limits(x=c(0.75, 7.25))
Run the code above in your browser using DataLab