1 ## plot.phylo.R (2011-12-03)
5 ## Copyright 2002-2011 Emmanuel Paradis
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
11 function(x, type = "phylogram", use.edge.length = TRUE,
12 node.pos = NULL, show.tip.label = TRUE,
13 show.node.label = FALSE, edge.color = "black",
14 edge.width = 1, edge.lty = 1, font = 3, cex = par("cex"),
15 adj = NULL, srt = 0, no.margin = FALSE, root.edge = FALSE,
16 label.offset = 0, underscore = FALSE, x.lim = NULL,
17 y.lim = NULL, direction = "rightwards", lab4ut = "horizontal",
18 tip.color = "black", plot = TRUE, rotate.tree = 0, ...)
20 Ntip <- length(x$tip.label)
22 warning("found only one tip in the tree")
25 if (any(tabulate(x$edge[, 1]) == 1))
26 stop("there are single (non-splitting) nodes in your tree; you may need to use collapse.singles()")
28 .nodeHeight <- function(Ntip, Nnode, edge, Nedge, yy)
29 .C("node_height", as.integer(Ntip), as.integer(Nnode),
30 as.integer(edge[, 1]), as.integer(edge[, 2]),
31 as.integer(Nedge), as.double(yy),
32 DUP = FALSE, PACKAGE = "ape")[[6]]
34 .nodeDepth <- function(Ntip, Nnode, edge, Nedge)
35 .C("node_depth", as.integer(Ntip), as.integer(Nnode),
36 as.integer(edge[, 1]), as.integer(edge[, 2]),
37 as.integer(Nedge), double(Ntip + Nnode),
38 DUP = FALSE, PACKAGE = "ape")[[6]]
40 .nodeDepthEdgelength <- function(Ntip, Nnode, edge, Nedge, edge.length)
41 .C("node_depth_edgelength", as.integer(Ntip),
42 as.integer(Nnode), as.integer(edge[, 1]),
43 as.integer(edge[, 2]), as.integer(Nedge),
44 as.double(edge.length), double(Ntip + Nnode),
45 DUP = FALSE, PACKAGE = "ape")[[7]]
47 Nedge <- dim(x$edge)[1]
50 type <- match.arg(type, c("phylogram", "cladogram", "fan",
51 "unrooted", "radial"))
52 direction <- match.arg(direction, c("rightwards", "leftwards",
53 "upwards", "downwards"))
54 if (is.null(x$edge.length)) use.edge.length <- FALSE
56 ## the order of the last two conditions is important:
57 if (type %in% c("unrooted", "radial") || !use.edge.length ||
58 is.null(x$root.edge) || !x$root.edge) root.edge <- FALSE
59 if (type == "fan" && root.edge) {
60 warning("drawing root edge with type = 'fan' is not yet supported")
64 phyloORclado <- type %in% c("phylogram", "cladogram")
65 horizontal <- direction %in% c("rightwards", "leftwards")
66 xe <- x$edge # to save
68 ## we first compute the y-coordinates of the tips.
69 phyOrder <- attr(x, "order")
70 ## make sure the tree is in cladewise order:
71 if (is.null(phyOrder) || phyOrder != "cladewise") {
72 x <- reorder(x) # fix from Klaus Schliep (2007-06-16)
73 if (!identical(x$edge, xe)) {
74 ## modified from Li-San Wang's fix (2007-01-23):
75 ereorder <- match(x$edge[, 2], xe[, 2])
76 if (length(edge.color) > 1) {
77 edge.color <- rep(edge.color, length.out = Nedge)
78 edge.color <- edge.color[ereorder]
80 if (length(edge.width) > 1) {
81 edge.width <- rep(edge.width, length.out = Nedge)
82 edge.width <- edge.width[ereorder]
84 if (length(edge.lty) > 1) {
85 edge.lty <- rep(edge.lty, length.out = Nedge)
86 edge.lty <- edge.lty[ereorder]
90 ### By contrats to ape (< 2.4), the arguments edge.color, etc., are
91 ### not elongated before being passed to segments(), except if needed
93 yy <- numeric(Ntip + Nnode)
94 TIPS <- x$edge[x$edge[, 2] <= Ntip, 2]
97 ## 'z' is the tree in pruningwise order used in calls to .C
98 z <- reorder(x, order = "pruningwise")
101 if (is.null(node.pos)) {
103 if (type == "cladogram" && !use.edge.length) node.pos <- 2
106 yy <- .nodeHeight(Ntip, Nnode, z$edge, Nedge, yy)
108 ## node_height_clado requires the number of descendants
109 ## for each node, so we compute `xx' at the same time
110 ans <- .C("node_height_clado", as.integer(Ntip),
111 as.integer(Nnode), as.integer(z$edge[, 1]),
112 as.integer(z$edge[, 2]), as.integer(Nedge),
113 double(Ntip + Nnode), as.double(yy),
114 DUP = FALSE, PACKAGE = "ape")
118 if (!use.edge.length) {
119 if (node.pos != 2) xx <- .nodeDepth(Ntip, Nnode, z$edge, Nedge) - 1
122 xx <- .nodeDepthEdgelength(Ntip, Nnode, z$edge, Nedge, z$edge.length)
125 rotate.tree <- 2 * pi * rotate.tree/360
126 switch(type, "fan" = {
127 ## if the tips are not in the same order in tip.label
128 ## and in edge[, 2], we must reorder the angles: we
129 ## use `xx' to store temporarily the angles
130 TIPS <- x$edge[which(x$edge[, 2] <= Ntip), 2]
131 xx <- seq(0, 2*pi*(1 - 1/Ntip), 2*pi/Ntip)
132 theta <- double(Ntip)
134 theta <- c(theta, numeric(Nnode))
135 theta <- .nodeHeight(Ntip, Nnode, z$edge, Nedge, theta)
136 if (use.edge.length) {
137 r <- .nodeDepthEdgelength(Ntip, Nnode, z$edge, Nedge, z$edge.length)
139 r <- .nodeDepth(Ntip, Nnode, z$edge, Nedge)
142 theta <- theta + rotate.tree
146 nb.sp <- .nodeDepth(Ntip, Nnode, z$edge, Nedge)
147 XY <- if (use.edge.length)
148 unrooted.xy(Ntip, Nnode, z$edge, z$edge.length, nb.sp, rotate.tree)
150 unrooted.xy(Ntip, Nnode, z$edge, rep(1, Nedge), nb.sp, rotate.tree)
151 ## rescale so that we have only positive values
152 xx <- XY$M[, 1] - min(XY$M[, 1])
153 yy <- XY$M[, 2] - min(XY$M[, 2])
155 X <- .nodeDepth(Ntip, Nnode, z$edge, Nedge)
159 ## angle (1st compute the angles for the tips):
160 yy <- c((1:Ntip)*2*pi/Ntip, rep(0, Nnode))
161 Y <- .nodeHeight(Ntip, Nnode, z$edge, Nedge, yy)
162 xx <- X * cos(Y + rotate.tree)
163 yy <- X * sin(Y + rotate.tree)
169 xx <- tmp - min(tmp) + 1
172 if (direction == "rightwards") xx <- xx + x$root.edge
173 if (direction == "upwards") yy <- yy + x$root.edge
176 if (no.margin) par(mai = rep(0, 4))
177 if (is.null(x.lim)) {
181 pin1 <- par("pin")[1] # width of the device in inches
182 strWi <- strwidth(x$tip.label, "inches") # id. for the tip labels
183 ## 1.04 comes from that we are using a regular axis system
184 ## with 4% on both sides of the range of x:
185 xx.tips <- xx[1:Ntip] * 1.04
186 ## 'alp' is the conversion coefficient from
187 ## user coordinates to inches:
188 alp <- try(uniroot(function(a) max(a*xx.tips + strWi) - pin1,
189 c(0, 1e6))$root, silent = TRUE)
190 ## if the above fails, give 1/3 of the device for the tip labels:
191 if (is.character(alp)) tmp <- max(xx.tips)*1.5 else {
192 tmp <- if (show.tip.label) max(xx.tips + strWi/alp) else max(xx.tips)
195 } else x.lim <- c(1, Ntip)
196 } else switch(type, "fan" = {
197 if (show.tip.label) {
198 offset <- max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
199 x.lim <- c(min(xx) - offset, max(xx) + offset)
200 } else x.lim <- c(min(xx), max(xx))
202 if (show.tip.label) {
203 offset <- max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
204 x.lim <- c(0 - offset, max(xx) + offset)
205 } else x.lim <- c(0, max(xx))
207 if (show.tip.label) {
208 offset <- max(nchar(x$tip.label) * 0.03 * cex)
209 x.lim <- c(-1 - offset, 1 + offset)
210 } else x.lim <- c(-1, 1)
212 } else if (length(x.lim) == 1) {
214 if (phyloORclado && !horizontal) x.lim[1] <- 1
215 if (type %in% c("fan", "unrooted") && show.tip.label)
216 x.lim[1] <- -max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
217 if (type == "radial")
219 if (show.tip.label) -1 - max(nchar(x$tip.label) * 0.03 * cex)
223 if (phyloORclado && direction == "leftwards") xx <- x.lim[2] - xx
224 if (is.null(y.lim)) {
226 if (horizontal) y.lim <- c(1, Ntip) else {
228 pin2 <- par("pin")[2] # height of the device in inches
229 strWi <- strwidth(x$tip.label, "inches")
230 ## 1.04 comes from that we are using a regular axis system
231 ## with 4% on both sides of the range of x:
232 yy.tips <- yy[1:Ntip] * 1.04
233 ## 'alp' is the conversion coefficient from
234 ## user coordinates to inches:
235 alp <- try(uniroot(function(a) max(a*yy.tips + strWi) - pin2,
236 c(0, 1e6))$root, silent = TRUE)
237 ## if the above fails, give 1/3 of the device for the tip labels:
238 if (is.character(alp)) tmp <- max(yy.tips)*1.5 else {
239 tmp <- if (show.tip.label) max(yy.tips + strWi/alp) else max(yy.tips)
243 } else switch(type, "fan" = {
244 if (show.tip.label) {
245 offset <- max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
246 y.lim <- c(min(yy) - offset, max(yy) + offset)
247 } else y.lim <- c(min(yy), max(yy))
249 if (show.tip.label) {
250 offset <- max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
251 y.lim <- c(0 - offset, max(yy) + offset)
252 } else y.lim <- c(0, max(yy))
254 if (show.tip.label) {
255 offset <- max(nchar(x$tip.label) * 0.03 * cex)
256 y.lim <- c(-1 - offset, 1 + offset)
257 } else y.lim <- c(-1, 1)
259 } else if (length(y.lim) == 1) {
261 if (phyloORclado && horizontal) y.lim[1] <- 1
262 if (type %in% c("fan", "unrooted") && show.tip.label)
263 y.lim[1] <- -max(nchar(x$tip.label) * 0.018 * max(yy) * cex)
264 if (type == "radial")
265 y.lim[1] <- if (show.tip.label) -1 - max(nchar(x$tip.label) * 0.018 * max(yy) * cex) else -1
268 if (phyloORclado && direction == "downwards") yy <- y.lim[2] - yy
269 if (phyloORclado && root.edge) {
270 if (direction == "leftwards") x.lim[2] <- x.lim[2] + x$root.edge
271 if (direction == "downwards") y.lim[2] <- y.lim[2] + x$root.edge
273 asp <- if (type %in% c("fan", "radial", "unrooted")) 1 else NA # fixes by Klaus Schliep (2008-03-28 and 2010-08-12)
274 plot(0, type = "n", xlim = x.lim, ylim = y.lim, ann = FALSE, axes = FALSE, asp = asp, ...)
278 adj <- if (phyloORclado && direction == "leftwards") 1 else 0
279 if (phyloORclado && show.tip.label) {
280 MAXSTRING <- max(strwidth(x$tip.label, cex = cex))
282 if (direction == "rightwards") {
283 lox <- label.offset + MAXSTRING * 1.05 * adj
285 if (direction == "leftwards") {
286 lox <- -label.offset - MAXSTRING * 1.05 * (1 - adj)
287 ##xx <- xx + MAXSTRING
291 MAXSTRING <- MAXSTRING * 1.09 * (psr[4] - psr[3])/(psr[2] - psr[1])
292 loy <- label.offset + MAXSTRING * 1.05 * adj
295 if (direction == "downwards") {
297 ##yy <- yy + MAXSTRING
302 if (type == "phylogram") {
303 phylogram.plot(x$edge, Ntip, Nnode, xx, yy,
304 horizontal, edge.color, edge.width, edge.lty)
307 ereorder <- match(z$edge[, 2], x$edge[, 2])
308 if (length(edge.color) > 1) {
309 edge.color <- rep(edge.color, length.out = Nedge)
310 edge.color <- edge.color[ereorder]
312 if (length(edge.width) > 1) {
313 edge.width <- rep(edge.width, length.out = Nedge)
314 edge.width <- edge.width[ereorder]
316 if (length(edge.lty) > 1) {
317 edge.lty <- rep(edge.lty, length.out = Nedge)
318 edge.lty <- edge.lty[ereorder]
320 circular.plot(z$edge, Ntip, Nnode, xx, yy, theta,
321 r, edge.color, edge.width, edge.lty)
323 cladogram.plot(x$edge, xx, yy, edge.color, edge.width, edge.lty)
327 "rightwards" = segments(0, yy[ROOT], x$root.edge, yy[ROOT]),
328 "leftwards" = segments(xx[ROOT], yy[ROOT], xx[ROOT] + x$root.edge, yy[ROOT]),
329 "upwards" = segments(xx[ROOT], 0, xx[ROOT], x$root.edge),
330 "downwards" = segments(xx[ROOT], yy[ROOT], xx[ROOT], yy[ROOT] + x$root.edge))
331 if (show.tip.label) {
332 if (is.expression(x$tip.label)) underscore <- TRUE
333 if (!underscore) x$tip.label <- gsub("_", " ", x$tip.label)
336 text(xx[1:Ntip] + lox, yy[1:Ntip] + loy, x$tip.label, adj = adj,
337 font = font, srt = srt, cex = cex, col = tip.color)
339 if (type == "unrooted") {
340 if (lab4ut == "horizontal") {
341 y.adj <- x.adj <- numeric(Ntip)
342 sel <- abs(XY$axe) > 0.75 * pi
343 x.adj[sel] <- -strwidth(x$tip.label)[sel] * 1.05
344 sel <- abs(XY$axe) > pi/4 & abs(XY$axe) < 0.75 * pi
345 x.adj[sel] <- -strwidth(x$tip.label)[sel] * (2 * abs(XY$axe)[sel] / pi - 0.5)
346 sel <- XY$axe > pi / 4 & XY$axe < 0.75 * pi
347 y.adj[sel] <- strheight(x$tip.label)[sel] / 2
348 sel <- XY$axe < -pi / 4 & XY$axe > -0.75 * pi
349 y.adj[sel] <- -strheight(x$tip.label)[sel] * 0.75
350 text(xx[1:Ntip] + x.adj * cex, yy[1:Ntip] + y.adj * cex,
351 x$tip.label, adj = c(adj, 0), font = font,
352 srt = srt, cex = cex, col = tip.color)
353 } else { # if lab4ut == "axial"
354 adj <- abs(XY$axe) > pi/2
355 srt <- 180 * XY$axe / pi
356 srt[adj] <- srt[adj] - 180
357 adj <- as.numeric(adj)
358 xx.tips <- xx[1:Ntip]
359 yy.tips <- yy[1:Ntip]
361 xx.tips <- xx.tips + label.offset * cos(XY$axe)
362 yy.tips <- yy.tips + label.offset * sin(XY$axe)
364 ## `srt' takes only a single value, so can't vectorize this:
365 ## (and need to 'elongate' these vectors:)
366 font <- rep(font, length.out = Ntip)
367 tip.color <- rep(tip.color, length.out = Ntip)
368 cex <- rep(cex, length.out = Ntip)
370 text(xx.tips[i], yy.tips[i], cex = cex[i],
371 x$tip.label[i], adj = adj[i], font = font[i],
372 srt = srt[i], col = tip.color[i])
375 if (type %in% c("fan", "radial")) {
376 xx.tips <- xx[1:Ntip]
377 yy.tips <- yy[1:Ntip]
378 ## using atan2 considerably facilitates things compared to acos...
379 angle <- atan2(yy.tips, xx.tips) # in radians
381 xx.tips <- xx.tips + label.offset * cos(angle)
382 yy.tips <- yy.tips + label.offset * sin(angle)
385 angle <- angle * 180/pi # switch to degrees
386 angle[s] <- angle[s] + 180
388 ## `srt' takes only a single value, so can't vectorize this:
389 ## (and need to 'elongate' these vectors:)
390 font <- rep(font, length.out = Ntip)
391 tip.color <- rep(tip.color, length.out = Ntip)
392 cex <- rep(cex, length.out = Ntip)
394 text(xx.tips[i], yy.tips[i], x$tip.label[i], font = font[i],
395 cex = cex[i], srt = angle[i], adj = adj[i],
400 text(xx[ROOT:length(xx)] + label.offset, yy[ROOT:length(yy)],
401 x$node.label, adj = adj, font = font, srt = srt, cex = cex)
403 L <- list(type = type, use.edge.length = use.edge.length,
404 node.pos = node.pos, show.tip.label = show.tip.label,
405 show.node.label = show.node.label, font = font,
406 cex = cex, adj = adj, srt = srt, no.margin = no.margin,
407 label.offset = label.offset, x.lim = x.lim, y.lim = y.lim,
408 direction = direction, tip.color = tip.color,
409 Ntip = Ntip, Nnode = Nnode)
410 assign("last_plot.phylo", c(L, list(edge = xe, xx = xx, yy = yy)),
411 envir = .PlotPhyloEnv)
415 phylogram.plot <- function(edge, Ntip, Nnode, xx, yy, horizontal,
416 edge.color, edge.width, edge.lty)
418 nodes <- (Ntip + 1):(Ntip + Nnode)
424 ## un trait vertical à chaque noeud...
426 y0v <- y1v <- numeric(Nnode)
427 ## store the index of each node in the 1st column of edge:
428 NodeInEdge1 <- vector("list", Nnode)
431 j <- NodeInEdge1[[ii]] <- which(edge[, 1] == i)
432 tmp <- range(yy[edge[j, 2]])
436 ## ... et un trait horizontal partant de chaque tip et chaque noeud
442 nc <- length(edge.color)
443 nw <- length(edge.width)
444 nl <- length(edge.lty)
446 if (nc + nw + nl == 3) {
447 color.v <- edge.color
448 width.v <- edge.width
451 Nedge <- dim(edge)[1]
452 edge.color <- rep(edge.color, length.out = Nedge)
453 edge.width <- rep(edge.width, length.out = Nedge)
454 edge.lty <- rep(edge.lty, length.out = Nedge)
455 DF <- data.frame(edge.color, edge.width, edge.lty, stringsAsFactors = FALSE)
456 color.v <- rep("black", Nnode)
457 width.v <- rep(1, Nnode)
458 lty.v <- rep(1, Nnode)
460 br <- NodeInEdge1[[i]]
461 if (length(br) > 2) {
462 x <- unique(DF[br, 1])
463 if (length(x) == 1) color.v[i] <- x
464 x <- unique(DF[br, 2])
465 if (length(x) == 1) width.v[i] <- x
466 x <- unique(DF[br, 3])
467 if (length(x) == 1) lty.v[i] <- x
471 if (any(DF[A, ] != DF[B, ])) {
472 color.v[i] <- edge.color[B]
473 width.v[i] <- edge.width[B]
474 lty.v[i] <- edge.lty[B]
476 y0v <- c(y0v, y0v[i])
477 y1v <- c(y1v, yy[i + Ntip])
478 x0v <- c(x0v, x0v[i])
479 color.v <- c(color.v, edge.color[A])
480 width.v <- c(width.v, edge.width[A])
481 lty.v <- c(lty.v, edge.lty[A])
483 y0v[i] <- yy[i + Ntip]
485 color.v[i] <- edge.color[A]
486 width.v[i] <- edge.width[A]
487 lty.v[i] <- edge.lty[A]
494 segments(x0h, y0h, x1h, y0h, col = edge.color, lwd = edge.width, lty = edge.lty) # draws horizontal lines
495 segments(x0v, y0v, x0v, y1v, col = color.v, lwd = width.v, lty = lty.v) # draws vertical lines
497 segments(y0h, x0h, y0h, x1h, col = edge.color, lwd = edge.width, lty = edge.lty) # draws vertical lines
498 segments(y0v, x0v, y1v, x0v, col = color.v, lwd = width.v, lty = lty.v) # draws horizontal lines
502 cladogram.plot <- function(edge, xx, yy, edge.color, edge.width, edge.lty)
503 segments(xx[edge[, 1]], yy[edge[, 1]], xx[edge[, 2]], yy[edge[, 2]],
504 col = edge.color, lwd = edge.width, lty = edge.lty)
506 circular.plot <- function(edge, Ntip, Nnode, xx, yy, theta,
507 r, edge.color, edge.width, edge.lty)
508 ### 'edge' must be in pruningwise order
512 theta0 <- theta[edge[, 2]]
513 costheta0 <- cos(theta0)
514 sintheta0 <- sin(theta0)
521 segments(x0, y0, x1, y1, col = edge.color, lwd = edge.width, lty = edge.lty)
523 tmp <- which(diff(edge[, 1]) != 0)
524 start <- c(1, tmp + 1)
525 Nedge <- dim(edge)[1]
528 ## function dispatching the features to the arcs
529 foo <- function(edge.feat, default) {
530 if (length(edge.feat) == 1) return(rep(edge.feat, Nnode))
532 edge.feat <- rep(edge.feat, length.out = Nedge)
533 feat.arc <- rep(default, Nnode)
535 tmp <- edge.feat[start[k]]
536 if (tmp == edge.feat[end[k]]) feat.arc[k] <- tmp
541 co <- foo(edge.color, "black")
542 lw <- foo(edge.width, 1)
543 ly <- foo(edge.lty, 1)
548 X <- rep(r[edge[i, 1]], 100)
549 Y <- seq(theta[edge[i, 2]], theta[edge[j, 2]], length.out = 100)
550 lines(X*cos(Y), X*sin(Y), col = co[k], lwd = lw[k], lty = ly[k])
554 unrooted.xy <- function(Ntip, Nnode, edge, edge.length, nb.sp, rotate.tree)
556 foo <- function(node, ANGLE, AXIS) {
557 ind <- which(edge[, 1] == node)
559 start <- AXIS - ANGLE/2
560 for (i in 1:length(sons)) {
561 h <- edge.length[ind[i]]
562 angle[sons[i]] <<- alpha <- ANGLE*nb.sp[sons[i]]/nb.sp[node]
563 axis[sons[i]] <<- beta <- start + alpha/2
564 start <- start + alpha
565 xx[sons[i]] <<- h*cos(beta) + xx[node]
566 yy[sons[i]] <<- h*sin(beta) + yy[node]
569 if (i > Ntip) foo(i, angle[i], axis[i])
571 Nedge <- dim(edge)[1]
572 yy <- xx <- numeric(Ntip + Nnode)
573 ## `angle': the angle allocated to each node wrt their nb of tips
574 ## `axis': the axis of each branch
575 axis <- angle <- numeric(Ntip + Nnode)
576 ## start with the root...
577 foo(Ntip + 1L, 2*pi, 0 + rotate.tree)
580 axe <- axis[1:Ntip] # the axis of the terminal branches (for export)
582 ## insures that returned angles are in [-PI, +PI]:
583 axe[axeGTpi] <- axe[axeGTpi] - 2*pi
584 list(M = M, axe = axe)
587 node.depth <- function(phy)
589 n <- length(phy$tip.label)
591 N <- dim(phy$edge)[1]
592 phy <- reorder(phy, order = "pruningwise")
593 .C("node_depth", as.integer(n), as.integer(m),
594 as.integer(phy$edge[, 1]), as.integer(phy$edge[, 2]),
595 as.integer(N), double(n + m), DUP = FALSE, PACKAGE = "ape")[[6]]
598 plot.multiPhylo <- function(x, layout = 1, ...)
601 layout(matrix(1:layout, ceiling(sqrt(layout)), byrow = TRUE))
602 else layout(matrix(1))
605 on.exit(par(ask = FALSE))
607 for (i in 1:length(x)) plot(x[[i]], ...)
610 trex <- function(phy, title = TRUE, subbg = "lightyellow3",
611 return.tree = FALSE, ...)
613 lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
614 devmain <- dev.cur() # where the main tree is plotted
616 restore <- function() {
618 assign("last_plot.phylo", lastPP, envir = .PlotPhyloEnv)
623 cat("Click close to a node. Right-click to exit.\n")
625 x <- identify.phylo(phy, quiet = TRUE)
626 if (is.null(x)) return(invisible(NULL)) else {
628 if (is.null(x)) cat("Try again!\n") else {
634 } else dev.set(devsub)
636 tr <- extract.clade(phy, x)
638 if (is.character(title)) title(title)
641 if (is.null(phy$node.label))
642 paste("From node #", x, sep = "")
643 else paste("From", phy$node.label[x - Ntip(phy)])
646 if (return.tree) return(tr)
653 kronoviz <- function(x, layout = length(x), horiz = TRUE, ...)
655 par(mar = rep(0.5, 4), oma = rep(2, 4))
656 rts <- sapply(x, function(x) branching.times(x)[1])
658 lim <- cbind(rts - maxrts, rts)
660 Ntips <- sapply(x, Ntip)
670 layout(matrix(1:layout, nrow), widths = w, heights = h)
671 if (layout > Ntree && !par("ask")) {
673 on.exit(par(ask = FALSE))
677 plot(x[[i]], x.lim = lim[i, ], ...)
680 plot(x[[i]], y.lim = lim[i, ], direction = "u", ...)
682 axisPhylo(if (horiz) 1 else 4) # better if the deepest tree is last ;)