]> git.donarmstrong.com Git - ape.git/blob - R/zoom.R
some bug fixes and '...' in rTrait*()
[ape.git] / R / zoom.R
1 ## zoom.R (2009-07-27)
2
3 ##   Zoom on a Portion of a Phylogeny
4
5 ## Copyright 2003-2009 Emmanuel Paradis
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 zoom <- function(phy, focus, subtree = FALSE, col = rainbow, ...)
11 {
12     if (!is.list(focus)) focus <- list(focus)
13     n <- length(focus)
14     for (i in 1:n)
15       if (is.character(focus[[i]]))
16         focus[[i]] <- which(phy$tip.label %in% focus[[i]]) # fix by Yan Wong
17     if (is.function(col)) {
18         col <- if (deparse(substitute(col)) == "grey") grey(1:n/n) else col(n)
19     }
20     ext <- vector("list", n)
21     for (i in 1:n)
22       ext[[i]] <- drop.tip(phy, phy$tip.label[-focus[[i]]],
23                            subtree = subtree, rooted = TRUE)
24     nc <- round(sqrt(n)) + 1
25     nr <- ceiling(sqrt(n))
26     M <- matrix(0, nr, nc)
27     x <- c(rep(1, nr), 2:(n + 1))
28     M[1:length(x)] <- x
29     layout(M, c(1, rep(3/(nc - 1), nc - 1)))
30     phy$tip.label <- rep("", length(phy$tip.label))
31     colo <- rep("black", dim(phy$edge)[1])
32     for (i in 1:n)
33       colo[which.edge(phy, focus[[i]])] <- col[i]
34     plot.phylo(phy, edge.color = colo, ...)
35     for (i in 1:n)
36       plot.phylo(ext[[i]], edge.color = col[i], ...)
37 }