Re: [S] modifying text.tree()

kjetil halvorsen (kjetil@caoba.entelnet.bo)
Fri, 24 Jul 1998 13:07:20 -0400


The tree object has component $frame, and values from this
can be used to label the tree. Give tree the optional argument
label= "name of component in $frame ".

You can also extend $frame with your own new
components. All of this is in the help
for text.

Kjetil Halvorsen

Don McKenzie escribió:
>
> Hi
>
> I would like to create a modified version of text.tree() to
> write back-transformed fitted values at the terminal nodes. For
> example: I am modeling proportional data using an arcsin/sqrt
> transformation, but would like to draw the tree with the original
> values printed at nodes. Has anyone done this, or identified the
> variable (which I can't seem to do) within text.tree() that
> corresponds to the values printed at nodes.
>
> Ideally, one would pass a function as additional argument to
> text.tree, as in: text.tree(<name of tree>,<function>), but
> I realize this creates scoping problems. I'd settle for just
> knowing what value(s) within the function to modify.
>
> Thanks much. I've attached the code to text.tree() below. I'm
> running v. 4.5 on Pentium2 NT with 128mb RAM.
>
> Don McKenzie
>
> *****************
>
> function(x, splits = T, label = "yval", FUN = text, all = F, pretty = NULL,
> digits
> = .Options$digits - 3, ...)
> {
> #Put left splits at the parent node
> #Allow labels at all or just leaf nodes
> #if FUN=text then adj=1 puts the split label to the left of the split
> rather than centered
> if(!inherits(x, "tree")) stop("Not legitimate tree")
> frame <- x$frame
> column <- names(frame)
> if(!is.null(ylevels <- attr(x, "ylevels")))
> column <- c(column, ylevels)
> if(is.na(match(label, column)))
> stop("Label must be a column label of the frame component of the tree"
> )
> cxy <- par("cxy")[2]
> if(!is.null(srt <- list(...)$srt) && srt == 90)
> cxy <- cxy * 4
> xy <- treeco(x)
> if(splits) {
> node <- as.numeric(row.names(frame))
> left.child <- match(2 * node, node)
> rows <- labels.tree(x, pretty = pretty)
> FUN(xy$x, xy$y + 0.5 * cxy, rows[left.child], ...)
> }
> leaves <- if(all) rep(T, nrow(frame)) else frame$var == "<leaf>"
> if(label == "yval" & !is.null(ylevels))
> stat <- as.character(frame$yval[leaves])
> else if(!is.null(ylevels) && !is.na(lev <- match(label, ylevels)))
> stat <- format(signif(frame$yprob[leaves, lev], digits = digits))
> else stat <- format(signif(frame[leaves, label], digits = digits))
> if(!is.null(dim(stat)) && dim(stat)[2] > 1) {
> if(length(dimnames(stat)[[2]]))
> stat[1, ] <- paste(sep = ":", dimnames(stat)[[2]], stat[1,
> ])
> stat <- do.call("paste", c(list(sep = "\n"), split(stat, col(stat)))
> )
> }
> FUN(xy$x[leaves], xy$y[leaves] - 0.5 * cxy, stat, ...)
> invisible()
> }
>
> __________________________________________________________
>
> DON MCKENZIE
>
> Research Ecologist
> College of Forest Resources, Box 352100
> University of Washington
> Seattle, WA 98195
>
> 206.543.9138
> 206.616.4015
> dmck@u.washington.edu
> http://silvae.cfr.washington.edu/people/dmck/home.html
>
> ___________________________________________________________
> -----------------------------------------------------------------------
> This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
> send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
> message: unsubscribe s-news
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news