1 ## plot.phylo.R (2009-09-23)
5 ## Copyright 2002-2009 Emmanuel Paradis
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
10 plot.phylo <- function(x, type = "phylogram", use.edge.length = TRUE,
11 node.pos = NULL, show.tip.label = TRUE,
12 show.node.label = FALSE, edge.color = "black",
13 edge.width = 1, edge.lty = 1, font = 3, cex = par("cex"),
14 adj = NULL, srt = 0, no.margin = FALSE,
15 root.edge = FALSE, label.offset = 0, underscore = FALSE,
16 x.lim = NULL, y.lim = NULL, direction = "rightwards",
17 lab4ut = "horizontal", tip.color = "black", ...)
19 Ntip <- length(x$tip.label)
21 warning("found only one tip in the tree")
24 if (any(tabulate(x$edge[, 1]) == 1))
25 stop("there are single (non-splitting) nodes in your tree; you may need to use collapse.singles()")
27 .nodeHeight <- function(Ntip, Nnode, edge, Nedge, yy)
28 .C("node_height", as.integer(Ntip), as.integer(Nnode),
29 as.integer(edge[, 1]), as.integer(edge[, 2]),
30 as.integer(Nedge), as.double(yy),
31 DUP = FALSE, PACKAGE = "ape")[[6]]
33 .nodeDepth <- function(Ntip, Nnode, edge, Nedge)
34 .C("node_depth", as.integer(Ntip), as.integer(Nnode),
35 as.integer(edge[, 1]), as.integer(edge[, 2]),
36 as.integer(Nedge), double(Ntip + Nnode),
37 DUP = FALSE, PACKAGE = "ape")[[6]]
39 .nodeDepthEdgelength <- function(Ntip, Nnode, edge, Nedge, edge.length)
40 .C("node_depth_edgelength", as.integer(Ntip),
41 as.integer(Nnode), as.integer(edge[, 1]),
42 as.integer(edge[, 2]), as.integer(Nedge),
43 as.double(edge.length), double(Ntip + Nnode),
44 DUP = FALSE, PACKAGE = "ape")[[7]]
46 Nedge <- dim(x$edge)[1]
49 type <- match.arg(type, c("phylogram", "cladogram", "fan",
50 "unrooted", "radial"))
51 direction <- match.arg(direction, c("rightwards", "leftwards",
52 "upwards", "downwards"))
53 if (is.null(x$edge.length)) use.edge.length <- FALSE
55 ## the order of the last two conditions is important:
56 if (type %in% c("unrooted", "radial") || !use.edge.length ||
57 is.null(x$root.edge) || !x$root.edge) root.edge <- FALSE
58 if (type == "fan" && root.edge) {
59 warning("drawing root edge with type = 'fan' is not yet supported")
63 phyloORclado <- type %in% c("phylogram", "cladogram")
64 horizontal <- direction %in% c("rightwards", "leftwards")
66 ## we first compute the y-coordinates of the tips.
67 phyOrder <- attr(x, "order")
68 ## make sure the tree is in cladewise order:
69 if (is.null(phyOrder) || phyOrder != "cladewise") {
71 x <- reorder(x) # fix from Klaus Schliep (2007-06-16)
72 if (!identical(x$edge, xe)) {
73 ## modified from Li-San Wang's fix (2007-01-23):
74 ereorder <- match(x$edge[, 2], xe[, 2])
75 if (length(edge.color) > 1) {
76 edge.color <- rep(edge.color, length.out = Nedge)
77 edge.color <- edge.color[ereorder]
79 if (length(edge.width) > 1) {
80 edge.width <- rep(edge.width, length.out = Nedge)
81 edge.width <- edge.width[ereorder]
83 if (length(edge.lty) > 1) {
84 edge.lty <- rep(edge.lty, length.out = Nedge)
85 edge.lty <- edge.lty[ereorder]
89 ### By contrats to ape (< 2.4), the arguments edge.color, etc., are
90 ### not elongated before being passed to segments(), except if needed
92 yy <- numeric(Ntip + Nnode)
93 TIPS <- x$edge[x$edge[, 2] <= Ntip, 2]
96 ## 'z' is the tree in pruningwise order used in calls to .C
97 z <- reorder(x, order = "pruningwise")
98 ### edge.color <- rep(edge.color, length.out = Nedge)
99 ### edge.width <- rep(edge.width, length.out = Nedge)
100 ### edge.lty <- rep(edge.lty, length.out = Nedge)
101 ### ## fix from Li-San Wang (2007-01-23):
103 ### x <- reorder(x, order = "pruningwise")
104 ### ereorder <- match(x$edge[, 2], xe[, 2])
105 ### edge.color <- edge.color[ereorder]
106 ### edge.width <- edge.width[ereorder]
107 ### edge.lty <- edge.lty[ereorder]
110 if (is.null(node.pos)) {
112 if (type == "cladogram" && !use.edge.length) node.pos <- 2
115 yy <- .nodeHeight(Ntip, Nnode, z$edge, Nedge, yy)
117 ## node_height_clado requires the number of descendants
118 ## for each node, so we compute `xx' at the same time
119 ans <- .C("node_height_clado", as.integer(Ntip),
120 as.integer(Nnode), as.integer(z$edge[, 1]),
121 as.integer(z$edge[, 2]), as.integer(Nedge),
122 double(Ntip + Nnode), as.double(yy),
123 DUP = FALSE, PACKAGE = "ape")
127 if (!use.edge.length) {
128 if (node.pos != 2) xx <- .nodeDepth(Ntip, Nnode, z$edge, Nedge) - 1
131 xx <- .nodeDepthEdgelength(Ntip, Nnode, z$edge, Nedge, z$edge.length)
135 ## if the tips are not in the same order in tip.label
136 ## and in edge[, 2], we must reorder the angles: we
137 ## use `xx' to store temporarily the angles
138 TIPS <- x$edge[which(x$edge[, 2] <= Ntip), 2]
139 xx <- seq(0, 2*pi*(1 - 1/Ntip), 2*pi/Ntip)
140 theta <- double(Ntip)
142 theta <- c(theta, numeric(Nnode))
143 theta <- .nodeHeight(Ntip, Nnode, z$edge, Nedge, theta)
144 if (use.edge.length) {
145 r <- .nodeDepthEdgelength(Ntip, Nnode, z$edge, Nedge, z$edge.length)
147 r <- .nodeDepth(Ntip, Nnode, z$edge, Nedge)
154 if (type == "unrooted") {
155 nb.sp <- .nodeDepth(Ntip, Nnode, z$edge, Nedge)
156 XY <- if (use.edge.length)
157 unrooted.xy(Ntip, Nnode, z$edge, z$edge.length, nb.sp)
159 unrooted.xy(Ntip, Nnode, z$edge, rep(1, Nedge), nb.sp)
160 ## rescale so that we have only positive values
161 xx <- XY$M[, 1] - min(XY$M[, 1])
162 yy <- XY$M[, 2] - min(XY$M[, 2])
164 if (type == "radial") {
165 X <- .nodeDepth(Ntip, Nnode, z$edge, Nedge)
169 ## angle (1st compute the angles for the tips):
170 yy <- c((1:Ntip)*2*pi/Ntip, rep(0, Nnode))
171 Y <- .nodeHeight(Ntip, Nnode, z$edge, Nedge, yy)
179 xx <- tmp - min(tmp) + 1
182 if (direction == "rightwards") xx <- xx + x$root.edge
183 if (direction == "upwards") yy <- yy + x$root.edge
186 if (no.margin) par(mai = rep(0, 4))
187 if (is.null(x.lim)) {
191 pin1 <- par("pin")[1] # width of the device in inches
192 strWi <- strwidth(x$tip.label, "inches") # id. for the tip labels
193 ## 1.04 comes from that we are using a regular axis system
194 ## with 4% on both sides of the range of x:
195 xx.tips <- xx[1:Ntip] * 1.04
196 ## 'alp' is the conversion coefficient from
197 ## user coordinates to inches:
198 alp <- try(uniroot(function(a) max(a*xx.tips + strWi) - pin1,
199 c(0, 1e6))$root, silent = TRUE)
200 ## if the above fails, give 1/3 of the device for the tip labels:
201 if (is.character(alp)) tmp <- max(xx.tips)*1.5 else {
202 tmp <- if (show.tip.label) max(xx.tips + strWi/alp) else max(xx.tips)
205 if (direction == "leftwards") xx <- x.lim[2] - xx #max(xx[ROOT] + tmp)
206 # else max(xx[1:Ntip] + tmp)
207 } else x.lim <- c(1, Ntip)
210 if (show.tip.label) {
211 offset <- max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
212 x.lim <- c(min(xx) - offset, max(xx) + offset)
213 } else x.lim <- c(min(xx), max(xx))
215 if (type == "unrooted") {
216 if (show.tip.label) {
217 offset <- max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
218 x.lim <- c(0 - offset, max(xx) + offset)
219 } else x.lim <- c(0, max(xx))
221 if (type == "radial") {
222 if (show.tip.label) {
223 offset <- max(nchar(x$tip.label) * 0.03 * cex)
224 x.lim <- c(-1 - offset, 1 + offset)
225 } else x.lim <- c(-1, 1)
227 } else if (length(x.lim) == 1) {
229 if (phyloORclado && !horizontal) x.lim[1] <- 1
230 if (type %in% c("fan", "unrooted") && show.tip.label)
231 x.lim[1] <- -max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
232 if (type == "radial")
234 if (show.tip.label) -1 - max(nchar(x$tip.label) * 0.03 * cex)
237 if (is.null(y.lim)) {
239 if (horizontal) y.lim <- c(1, Ntip) else {
241 pin2 <- par("pin")[2] # height of the device in inches
242 strWi <- strwidth(x$tip.label, "inches")
243 ## 1.04 comes from that we are using a regular axis system
244 ## with 4% on both sides of the range of x:
245 yy.tips <- yy[1:Ntip] * 1.04
246 ## 'alp' is the conversion coefficient from
247 ## user coordinates to inches:
248 alp <- try(uniroot(function(a) max(a*yy.tips + strWi) - pin2,
249 c(0, 1e6))$root, silent = TRUE)
250 ## if the above fails, give 1/3 of the device for the tip labels:
251 if (is.character(alp)) tmp <- max(yy.tips)*1.5 else {
252 tmp <- if (show.tip.label) max(yy.tips + strWi/alp) else max(yy.tips)
255 if (direction == "downwards") yy <- y.lim[2] - yy
259 if (show.tip.label) {
260 offset <- max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
261 y.lim <- c(min(yy) - offset, max(yy) + offset)
262 } else y.lim <- c(min(yy), max(yy))
264 if (type == "unrooted") {
265 if (show.tip.label) {
266 offset <- max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
267 y.lim <- c(0 - offset, max(yy) + offset)
268 } else y.lim <- c(0, max(yy))
270 if (type == "radial") {
271 if (show.tip.label) {
272 offset <- max(nchar(x$tip.label) * 0.03 * cex)
273 y.lim <- c(-1 - offset, 1 + offset)
274 } else y.lim <- c(-1, 1)
276 } else if (length(y.lim) == 1) {
278 if (phyloORclado && horizontal) y.lim[1] <- 1
279 if (type %in% c("fan", "unrooted") && show.tip.label)
280 y.lim[1] <- -max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
281 if (type == "radial")
282 y.lim[1] <- if (show.tip.label) -1 - max(nchar(x$tip.label) * 0.018 * max(yy) * cex) else -1
284 if (phyloORclado && root.edge) {
285 if (direction == "leftwards") x.lim[2] <- x.lim[2] + x$root.edge
286 if (direction == "downwards") y.lim[2] <- y.lim[2] + x$root.edge
288 ## fix by Klaus Schliep (2008-03-28):
289 asp <- if (type %in% c("fan", "radial")) 1 else NA
290 plot(0, type = "n", xlim = x.lim, ylim = y.lim, ann = FALSE, axes = FALSE, asp = asp, ...)
292 adj <- if (phyloORclado && direction == "leftwards") 1 else 0
293 if (phyloORclado && show.tip.label) {
294 MAXSTRING <- max(strwidth(x$tip.label, cex = cex))
296 if (direction == "rightwards") {
297 lox <- label.offset + MAXSTRING * 1.05 * adj
299 if (direction == "leftwards") {
300 lox <- -label.offset - MAXSTRING * 1.05 * (1 - adj)
301 #xx <- xx + MAXSTRING
305 MAXSTRING <- MAXSTRING * 1.09 * (psr[4] - psr[3])/(psr[2] - psr[1])
306 loy <- label.offset + MAXSTRING * 1.05 * adj
309 if (direction == "downwards") {
311 ##yy <- yy + MAXSTRING
316 if (type == "phylogram") {
317 phylogram.plot(x$edge, Ntip, Nnode, xx, yy,
318 horizontal, edge.color, edge.width, edge.lty)
321 ereorder <- match(z$edge[, 2], x$edge[, 2])
322 if (length(edge.color) > 1) {
323 edge.color <- rep(edge.color, length.out = Nedge)
324 edge.color <- edge.color[ereorder]
326 if (length(edge.width) > 1) {
327 edge.width <- rep(edge.width, length.out = Nedge)
328 edge.width <- edge.width[ereorder]
330 if (length(edge.lty) > 1) {
331 edge.lty <- rep(edge.lty, length.out = Nedge)
332 edge.lty <- edge.lty[ereorder]
334 circular.plot(z$edge, Ntip, Nnode, xx, yy, theta,
335 r, edge.color, edge.width, edge.lty)
337 cladogram.plot(x$edge, xx, yy, edge.color, edge.width, edge.lty)
341 "rightwards" = segments(0, yy[ROOT], x$root.edge, yy[ROOT]),
342 "leftwards" = segments(xx[ROOT], yy[ROOT], xx[ROOT] + x$root.edge, yy[ROOT]),
343 "upwards" = segments(xx[ROOT], 0, xx[ROOT], x$root.edge),
344 "downwards" = segments(xx[ROOT], yy[ROOT], xx[ROOT], yy[ROOT] + x$root.edge))
345 if (show.tip.label) {
346 if (!underscore) x$tip.label <- gsub("_", " ", x$tip.label)
349 text(xx[1:Ntip] + lox, yy[1:Ntip] + loy, x$tip.label, adj = adj,
350 font = font, srt = srt, cex = cex, col = tip.color)
352 if (type == "unrooted") {
353 if (lab4ut == "horizontal") {
354 y.adj <- x.adj <- numeric(Ntip)
355 sel <- abs(XY$axe) > 0.75 * pi
356 x.adj[sel] <- -strwidth(x$tip.label)[sel] * 1.05
357 sel <- abs(XY$axe) > pi/4 & abs(XY$axe) < 0.75 * pi
358 x.adj[sel] <- -strwidth(x$tip.label)[sel] * (2 * abs(XY$axe)[sel] / pi - 0.5)
359 sel <- XY$axe > pi / 4 & XY$axe < 0.75 * pi
360 y.adj[sel] <- strheight(x$tip.label)[sel] / 2
361 sel <- XY$axe < -pi / 4 & XY$axe > -0.75 * pi
362 y.adj[sel] <- -strheight(x$tip.label)[sel] * 0.75
363 text(xx[1:Ntip] + x.adj*cex, yy[1:Ntip] + y.adj*cex,
364 x$tip.label, adj = c(adj, 0), font = font,
365 srt = srt, cex = cex, col = tip.color)
366 } else { # if lab4ut == "axial"
367 adj <- as.numeric(abs(XY$axe) > pi/2)
369 srt[as.logical(adj)] <- srt[as.logical(adj)] - 180
370 ## `srt' takes only a single value, so can't vectorize this:
372 text(xx[i], yy[i], cex = cex, x$tip.label[i], adj = adj[i],
373 font = font, srt = srt[i], col = tip.color[i])
376 if (type %in% c("fan", "radial")) {
377 xx.scaled <- xx[1:Ntip]
378 if (type == "fan") { # no need if type == "radial"
379 maxx <- max(abs(xx.scaled))
380 if (maxx > 1) xx.scaled <- xx.scaled/maxx
382 angle <- acos(xx.scaled)*180/pi
383 s1 <- angle > 90 & yy[1:Ntip] > 0
384 s2 <- angle < 90 & yy[1:Ntip] < 0
385 s3 <- angle > 90 & yy[1:Ntip] < 0
386 angle[s1] <- angle[s1] + 180
387 angle[s2] <- -angle[s2]
388 angle[s3] <- 180 - angle[s3]
390 adj[xx[1:Ntip] < 0] <- 1
391 ## `srt' takes only a single value, so can't vectorize this:
393 text(xx[i], yy[i], x$tip.label[i], font = font, cex = cex,
394 srt = angle[i], adj = adj[i], col = tip.color[i])
398 text(xx[ROOT:length(xx)] + label.offset, yy[ROOT:length(yy)],
399 x$node.label, adj = adj, font = font, srt = srt, cex = cex)
400 L <- list(type = type, use.edge.length = use.edge.length,
401 node.pos = node.pos, show.tip.label = show.tip.label,
402 show.node.label = show.node.label, font = font,
403 cex = cex, adj = adj, srt = srt, no.margin = no.margin,
404 label.offset = label.offset, x.lim = x.lim, y.lim = y.lim,
405 direction = direction, tip.color = tip.color,
406 Ntip = Ntip, Nnode = Nnode)
407 assign("last_plot.phylo", c(L, list(edge = x$edge, xx = xx, yy = yy)),
408 envir = .PlotPhyloEnv)
412 phylogram.plot <- function(edge, Ntip, Nnode, xx, yy, horizontal,
413 edge.color, edge.width, edge.lty)
415 nodes <- (Ntip + 1):(Ntip + Nnode)
421 ## un trait vertical à chaque noeud...
423 y0v <- y1v <- numeric(Nnode)
424 ## store the index of each node in the 1st column of edge:
425 NodeInEdge1 <- vector("list", Nnode)
428 j <- NodeInEdge1[[ii]] <- which(edge[, 1] == i)
429 tmp <- range(yy[edge[j, 2]])
433 ## ... et un trait horizontal partant de chaque tip et chaque noeud
435 ### sq <- c(1:Ntip, nodes[-1])
438 ### ## match() is very useful here becoz each element in edge[, 2] is
439 ### ## unique (not sure this is so useful in edge[, 1]; needs to be checked)
440 ### ## `pos' gives for each element in `sq' its index in edge[, 2]
441 ### pos <- match(sq, edge[, 2])
442 ### x0h <- xx[edge[pos, 1]]
446 ### donc plus besoin de 'pos' ni 'sq'
448 nc <- length(edge.color)
449 nw <- length(edge.width)
450 nl <- length(edge.lty)
452 if (nc + nw + nl == 3) {
453 color.v <- edge.color
454 width.v <- edge.width
457 Nedge <- dim(edge)[1]
458 edge.color <- rep(edge.color, length.out = Nedge)
459 edge.width <- rep(edge.width, length.out = Nedge)
460 edge.lty <- rep(edge.lty, length.out = Nedge)
461 DF <- data.frame(edge.color, edge.width, edge.lty)
462 color.v <- rep("black", Nnode)
463 width.v <- rep(1, Nnode)
464 lty.v <- rep(1, Nnode)
466 br <- NodeInEdge1[[i]]
467 if (length(br) > 2) {
468 x <- unique(DF[br, 1])
469 if (length(x) == 1) color.v[i] <- x
470 x <- unique(DF[br, 2])
471 if (length(x) == 1) width.v[i] <- x
472 x <- unique(DF[br, 3])
473 if (length(x) == 1) lty.v[i] <- x
477 if (any(DF[A, ] != DF[B, ])) {
478 color.v[i] <- edge.color[B]
479 width.v[i] <- edge.width[B]
480 lty.v[i] <- edge.lty[B]
482 y0v <- c(y0v, y0v[i])
483 y1v <- c(y1v, yy[i + Ntip])
484 x0v <- c(x0v, x0v[i])
485 color.v <- c(color.v, edge.color[A])
486 width.v <- c(width.v, edge.width[A])
487 lty.v <- c(lty.v, edge.lty[A])
489 y0v[i] <- yy[i + Ntip]
491 color.v[i] <- edge.color[A]
492 width.v[i] <- edge.width[A]
493 lty.v[i] <- edge.lty[A]
499 ### ## function dispatching the features to the vertical edges
500 ### foo <- function(edge.feat, default) {
501 ### e <- unique(edge.feat)
502 ### if (length(e) == 1) return(rep(e, Nnode))
504 ### feat.v <- rep(default, Nnode)
505 ### for (i in 1:Nnode) {
506 ### br <- NodeInEdge1[[i]]
507 ### if (length(br) > 2) {
508 ### x <- unique(edge.feat[br])
509 ### if (length(x) == 1) feat.v[i] <- x
511 ### if (edge.feat[br[1]] == edge.feat[br[2]])
512 ### feat.v[i] <- edge.feat[br[1]]
514 ### feat.v[i] <- edge.feat[br[2]]
515 ### ## add a new line:
516 ### y0v <<- c(y0v, y0v[i])
517 ### y1v <<- c(y1v, yy[i + Ntip])
518 ### x0v <<- c(x0v, x0v[i])
519 ### feat.v <- c(feat.v, edge.feat[br[1]])
520 ### ## shorten the line:
521 ### y0v[i] <<- yy[i + Ntip]
528 ### color.v <- foo(edge.color, "black")
529 ### width.v <- foo(edge.width, 1)
530 ### lty.v <- foo(edge.lty, 1)
532 ### ## we need to reorder:
533 ### edge.width <- edge.width[pos]
534 ### edge.color <- edge.color[pos]
535 ### edge.lty <- edge.lty[pos]
538 segments(x0h, y0h, x1h, y0h, col = edge.color, lwd = edge.width, lty = edge.lty) # draws horizontal lines
539 segments(x0v, y0v, x0v, y1v, col = color.v, lwd = width.v, lty = lty.v) # draws vertical lines
541 segments(y0h, x0h, y0h, x1h, col = edge.color, lwd = edge.width, lty = edge.lty) # draws vertical lines
542 segments(y0v, x0v, y1v, x0v, col = color.v, lwd = width.v, lty = lty.v) # draws horizontal lines
546 cladogram.plot <- function(edge, xx, yy, edge.color, edge.width, edge.lty)
547 segments(xx[edge[, 1]], yy[edge[, 1]], xx[edge[, 2]], yy[edge[, 2]],
548 col = edge.color, lwd = edge.width, lty = edge.lty)
550 circular.plot <- function(edge, Ntip, Nnode, xx, yy, theta,
551 r, edge.color, edge.width, edge.lty)
552 ### 'edge' must be in pruningwise order
556 theta0 <- theta[edge[, 2]]
557 costheta0 <- cos(theta0)
558 sintheta0 <- sin(theta0)
565 segments(x0, y0, x1, y1, col = edge.color, lwd = edge.width, lty = edge.lty)
567 tmp <- which(diff(edge[, 1]) != 0)
568 start <- c(1, tmp + 1)
569 Nedge <- dim(edge)[1]
572 ## function dispatching the features to the arcs
573 foo <- function(edge.feat, default) {
574 if (length(edge.feat) == 1) return(rep(edge.feat, Nnode))
576 edge.feat <- rep(edge.feat, length.out = Nedge)
577 feat.arc <- rep(default, Nnode)
579 tmp <- edge.feat[start[k]]
580 if (tmp == edge.feat[end[k]]) feat.arc[k] <- tmp
585 co <- foo(edge.color, "black")
586 lw <- foo(edge.width, 1)
587 ly <- foo(edge.lty, 1)
592 X <- rep(r[edge[i, 1]], 100)
593 Y <- seq(theta[edge[i, 2]], theta[edge[j, 2]], length.out = 100)
594 lines(X*cos(Y), X*sin(Y), col = co[k], lwd = lw[k], lty = ly[k])
598 unrooted.xy <- function(Ntip, Nnode, edge, edge.length, nb.sp)
600 foo <- function(node, ANGLE, AXIS) {
601 ind <- which(edge[, 1] == node)
603 start <- AXIS - ANGLE/2
604 for (i in 1:length(sons)) {
605 h <- edge.length[ind[i]]
606 angle[sons[i]] <<- alpha <- ANGLE*nb.sp[sons[i]]/nb.sp[node]
607 axis[sons[i]] <<- beta <- start + alpha/2
608 start <- start + alpha
609 xx[sons[i]] <<- h*cos(beta) + xx[node]
610 yy[sons[i]] <<- h*sin(beta) + yy[node]
613 if (i > Ntip) foo(i, angle[i], axis[i])
615 Nedge <- dim(edge)[1]
616 yy <- xx <- numeric(Ntip + Nnode)
617 ## `angle': the angle allocated to each node wrt their nb of tips
618 ## `axis': the axis of each branch
619 axis <- angle <- numeric(Ntip + Nnode)
620 ## start with the root...
621 foo(Ntip + 1L, 2*pi, 0)
624 axe <- axis[1:Ntip] # the axis of the terminal branches (for export)
626 ## insures that returned angles are in [-PI, +PI]:
627 axe[axeGTpi] <- axe[axeGTpi] - 2*pi
628 list(M = M, axe = axe)
631 node.depth <- function(phy)
633 n <- length(phy$tip.label)
635 N <- dim(phy$edge)[1]
636 phy <- reorder(phy, order = "pruningwise")
637 .C("node_depth", as.integer(n), as.integer(m),
638 as.integer(phy$edge[, 1]), as.integer(phy$edge[, 2]),
639 as.integer(N), double(n + m), DUP = FALSE, PACKAGE = "ape")[[6]]
642 plot.multiPhylo <- function(x, layout = 1, ...)
645 layout(matrix(1:layout, ceiling(sqrt(layout)), byrow = TRUE))
646 else layout(matrix(1))
649 on.exit(par(ask = FALSE))
651 for (i in x) plot(i, ...)