]> git.donarmstrong.com Git - ape.git/blob - R/zoom.R
current 2.1 release
[ape.git] / R / zoom.R
1 ## zoom.R (2004-12-17)
2
3 ##   Zoom on a Portion of a Phylogeny
4
5 ## Copyright 2003-2004 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 == focus[[i]])
17     if (is.function(col))
18       if (deparse(substitute(col)) == "grey")
19         col <- grey(1:n/n) else col <- col(n)
20     ext <- list()
21     length(ext) <- n
22     for (i in 1:n)
23       ext[[i]] <- drop.tip(phy, phy$tip.label[-focus[[i]]],
24                            subtree = subtree)
25     nc <- round(sqrt(n)) + 1
26     nr <- ceiling(sqrt(n))
27     M <- matrix(0, nr, nc)
28     x <- c(rep(1, nr), 2:(n + 1))
29     M[1:length(x)] <- x
30     layout(M, c(1, rep(3 / (nc - 1), nc - 1)))
31     phy$tip.label <- rep("", length(phy$tip.label))
32     colo <- rep("black", dim(phy$edge)[1])
33     for (i in 1:n)
34       colo[which.edge(phy, focus[[i]])] <- col[i]
35     plot.phylo(phy, edge.color = colo, ...)
36     for (i in 1:n)
37       plot.phylo(ext[[i]], edge.color = col[i], ...)
38 }