Skip to content
Prev 171714 / 398503 Next

how to label the branches of a tree

Following Dr Ripley's advice I looked at the text.rpart documentation  
a bit more thoroughly and after seeing "The edges connecting the nodes  
are labeled by left and right splits." I find that the fancy=TRUE  
invocation does cause a labeling of what you appear to be calling  
"branches".

See if this minor modification of the rpart example code produces your  
desired result:

library(rpart)
fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)
par(mfrow=c(1,1), xpd=NA)  # otherwise on some devices the text is  
clipped
plot(fit)
text(fit, use.n=TRUE, fancy=TRUE)

On my "devices" (Mac OS X 10.5.6, R 2.8.1, quartz) the boxes around  
the leaf labels are a bit too low on the default screen device, and  
sending the output to a pdf file does not correct that problem, but as  
always the code is there for you to work with.