[R] plot rpart tree's from list object

Christian Schulz ozric at web.de
Thu Jun 5 08:57:25 CEST 2003


....many Thanks!
For another lazzy typist's - this works  fine.

for (i in 1:length(tList)) {
post(tList[[i]],paste("Tree", i, "ps", sep="."), title="title",
digits=getOption("digits") - 0,use.n=TRUE)
graphics.off()
}

christian


> Yes, you need dev.off() inside the loop and to name the files differently.
>
> It's title. to avoid complaints about masking functions of the same name,
> in long-ago versions of S3 and R.
>
> On Wed, 4 Jun 2003, Thomas W Blackwell wrote:
>
> > Christian  -
> >
> > I am looking at the call to  post()  in the code fragment below,
> > and I wonder whether all of the arguments that are supplied will
> > be matched correctly.  I am also reading  help("post.rpart").
> >
> > The first argument is the tree, and that should be matched okay.
> > The second argument in the help is named "title.".  It's unusual
> > to include a period explicitly at the end of an argument name,
> > and I wonder whether maybe it's needed in order to distinguish
> > this use of "title" from that in some other function ?
> >
> > However, the second example at the bottom of the help page seems
> > to succeed in spite of using "title" without the dot, and it passes
> > the arguments in the same order as shown in your example ...
> >
> > Hmmmm.   There are three experiments I would try, if this were
> > my problem - and NO guarantees that any of them will solve it:
> >
> > (1) Pass arguments in exactly the order they appear in the
> > post.rpart() function definition, and use the dot in "title.".
> > The order is:  tree, title., filename, digits, pretty, use.n, ... .
> > (This is from R 1.6.2.  Type  post.rpart  (no parentheses) at
> > the command line prompt to see the function definition in the
> > version you are using.
> >
> > (2) Try typing  graphics.off()  at the command line prompt
> > after the loop has finished.  This is needed in order to get
> > the last plot into the output file if you have used the
> > function  postscript()  from base R.
> >
> > (3) Observe that all 18 filenames generated by  paste() will
> > be the same.  I think that  paste("Tree","i",sep=".ps")  will
> > produce  "Tree.psi"  every time.  The i is not interpreted
> > because it is in quotes.  So each new plot overwrites the
> > previous one.  An alternative might be:
> > paste("Tree", i, "ps", sep=".")  giving eg  "Tree.18.ps".
> >
> > HTH  -  tom blackwell  -  u michigan medical school  -  ann arbor  -
> >
> >
> > On Wed, 4 Jun 2003, Christian Schulz wrote:
> >
> > > i want the post plot's from a rpart list object with
> > > 18 tree's , getting no error - but getting no files,too?
> > > Perhaps i should using assign!?
> > >
> > > for (i in 1:length(treeList)) {
> > > post(treeList[[i]],filename=paste("Tree","i",sep=".ps"),
title="Arbeitszufriedenheit",
> > > digits=getOption("digits") - 0,use.n=TRUE)
> > > }
> > >
> > > many thanks for help,
> > > christian
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >
>
> --
> 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