plot.tree.EJN <- function (x, y = NULL, type = c("proportional", "uniform"), scale = 1,...) { if (inherits(x, "singlenode")) stop("cannot plot singlenode tree") if (!inherits(x, "tree")) stop("not legitimate tree") type <- match.arg(type) uniform <- type == "uniform" dev <- dev.cur() if (dev == 1) dev <- 2 assign(paste(".Tree.unif", dev, sep = "."), uniform, envir = .GlobalEnv) #EJN>>> Tell the environment the current scale assign(paste(".Tree.scale", dev, sep = "."), scale, envir=.GlobalEnv) #<<>> Get the current scale if(exists(scale)) scale <- get(scale) else scale <- 1 #<<>> Apply the scale x.range <- range(x)/scale y.range <- range(y)/scale plot(x.range - diff(x.range)*(1 - scale)/2, y.range + diff(y.range)*(1 - scale)/2, type = "n", axes = FALSE, xlab = "", ylab = "") #<<" x[leaves] <- seq(sum(leaves)) depth <- split(seq(node)[!leaves], depth[!leaves]) left.child <- match(node * 2, node) right.child <- match(node * 2 + 1, node) for (i in rev(depth)) x[i] <- 0.5 * (x[left.child[i]] + x[right.child[i]]) list(x = x, y = y) } tree.depth <- function (nodes) { depth <- floor(log(nodes, base = 2) + 1e-07) as.vector(depth - min(depth)) }