"Brian Jensvold" <bjensv...@hawesfinancial.com> het geskryf
I am trying to create a classification tree using either tree or rpart
but when it comes to plotting the results the formatting I get is
different than what I see in all the tutorials.  What I would like to
see is the XX/XX format but all I get is a weird decimal value.

The rpart.plot package provides more flexible routines for plotting
rpart trees than the rpart package itself.  Use rpart.plot with
extra=3 to get the XX/XX format you want:

library(rpart.plot)
data(ptitanic)
tree <- rpart(survived ~ ., data=ptitanic)
rpart.plot(tree, extra=3)

See also page 4 of the vignette for the rpart.plot package.

I was also wondering how you know which is yes and which is no in each
leaf of the tree?  Is yes always on the left?

rpart.plot annotates the top label with Yes and No to remind viewers
that left is yes.  To flip that use

rpart.plot(tree, extra=3, left=FALSE)

But such flipping may not be a good idea -- if your audience is used
to plot.rpart they will expect yes on the left.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to