]> git.donarmstrong.com Git - ape.git/blob - R/subtreeplot.R
fixing drop.tip and bionj
[ape.git] / R / subtreeplot.R
1 ## subtreeplot.R (2008-04-30)
2
3 ##  Zoom on a Portion of a Phylogeny by Successive Clicks
4
5 ## Copyright 2008 Damien de Vienne
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 subtreeplot<-function(x, wait=FALSE, ...) {
11
12     sub<-subtrees(x, wait=wait)
13     y<-NULL
14     plot.default(0, type="n",axes=FALSE, ann=FALSE)
15     repeat {
16           split.screen(c(1,2))
17         screen(2)
18         if (is.null(y)) plot(x,...)
19         else plot(y,sub=paste("Node :", click),...)
20         screen(1)
21         plot(x,sub="Complete tree",main="Type ESC or right click to exit", cex.main=0.9, ...)
22
23         N.tip<-Ntip(x)
24         N.node<-Nnode(x)
25
26         coor<-plotPhyloCoor(x)
27         tips<-x$tip.label
28         nodes<-x$node.label
29         if (is.null(x$node.label)) nodes<-(N.tip+1):(N.tip+N.node)
30         labs<-c(rep("",N.tip), nodes)
31
32         click<-identify(coor[,1], coor[,2], labels=labs, n=1)
33         if (length(click) == 0) {return(y)}
34         if (click > N.tip) {
35             close.screen(c(1,2),all.screens = TRUE)
36             split.screen(c(1,2))
37             screen(1) #selects the screen to plot in
38             plot(x, sub="Complete tree", ...) # plots x in screen 1 (left)
39             screen(2)
40             for (i in 1:length(sub)) if (sub[[i]]$name==click) break
41             y<-sub[[i]]
42           }
43         else cat("this is a tip, you have to choose a node\n")
44
45       }
46     on.exit(return(y))
47 }