[R] Rpart question - labeling nodes with something not in x$frame

Ko-Kang Kevin Wang kwan022 at stat.auckland.ac.nz
Thu Jul 17 22:27:44 CEST 2003


On Thu, 17 Jul 2003, Peter Flom wrote:

> I have a tree created with
> 
> tr.hh.logcas <- rpart(log(YCASSX + 1)~AGE+DRUGUSEY+SEX+OBSXNUM +WINDLE,
> xval = 10)
> 
> I would like to label the nodes with YCASSX rather than log(YCASSX +
> 1).  But the help file for text in library rpart says that you can only
> use labels that are part of x$frame, which YCASSX is not.

This may not be the best solution, but what I have done once is to add 
another column into the data frame with the labels I want.

For example:
  data(iris)
  library(rpart)
  # Recoding the response:
  #    s: setosa
  #    c: versicolor
  #    v: virginica
  ir <- iris[, -5]
  Species <- rep(c("s", "c", "v"), rep(50, 3))
  ir <- as.data.frame(cbind(ir, Species))
  ir.rp <- rpart(Species ~ ., data = ir)
  plot(ir.rp)
  text(ir.rp)

This is probably the long/silly way, but it works ;-D

-- 
Cheers,

Kevin

------------------------------------------------------------------------------
"On two occasions, I have been asked [by members of Parliament],
'Pray, Mr. Babbage, if you put into the machine wrong figures, will
the right answers come out?' I am not able to rightly apprehend the
kind of confusion of ideas that could provoke such a question."

-- Charles Babbage (1791-1871) 
---- From Computer Stupidities: http://rinkworks.com/stupid/

--
Ko-Kang Kevin Wang
Master of Science (MSc) Student
SLC Tutor and Lab Demonstrator
Department of Statistics
University of Auckland
New Zealand
Homepage: http://www.stat.auckland.ac.nz/~kwan022
Ph: 373-7599
    x88475 (City)
    x88480 (Tamaki)




More information about the R-help mailing list