[R] how to label the branches of a tree

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Feb 25 14:42:27 CET 2009


On Wed, 25 Feb 2009, David Winsemius wrote:

> When I execute that code, I get labels both on the branching points and at 
> the leaves of the tree. So I guess my reply is "cannot reproduce" or "do not 
> understand".  They are however not properly positioned and the edges and 
> bottoms of some of the labels are cut off, but that did not sound like your 
> question.

Try par(xpd), as mentioned in the help (?text.rpart): that also 
mentions a lot more ways to control the plot's appearance.

> Using Mac OS X 10.5.6 and the ATT binary of R2.8.1. ‘rpart’ version 3.1-42.

The graphics device matters too.

>
> -- 
> David Winsemius
>
> Note:  your mailer is putting single quotes inside the enclosing angle 
> brackets so my mailer does not recognize the r-help address as a valid 
> address. Since this is the first time I have encountered this construction, I 
> wonder if your mailer is adhering to standards in its reply-to functions.
>
>
>
> On Feb 25, 2009, at 1:19 AM, Utkarsh Singhal wrote:
>
>> Hi,
>> 
>> 
>> 
>> I am using rpart package to fit classification trees.
>> 
>> 
>> 
>> library(rpart)
>> 
>> fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)
>> 
>> plot(fit,uniform=T)
>> 
>> text(fit, use.n=TRUE)
>> 
>> 
>> But I am unable to label the branches (not the nodes) of the tree. Can 
>> somebody help me out in this?
>> 
>> 
>> 
>> Thank you,
>> 
>> Regards
>> 
>> Utkarsh Singhal | Amba Research

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list