]> git.donarmstrong.com Git - ape.git/blob - R/plot.ancestral.R
few corrections and fixes
[ape.git] / R / plot.ancestral.R
1 ## plot.ancestral.R (2005-12-04)
2
3 ##   Plotting Ancestral Characters on a Tree
4
5 ## Copyright 2005 Julien Dutheil
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 plot.ancestral <- function(x, which=names(x$node.character),
11     n.col=10, col.fun=function(n) rainbow(n, start=0.4, end=0),
12     plot.node.values=FALSE,
13     ask = prod(par("mfcol")) < length(which) && dev.interactive(),
14     ...)
15 {
16   if (!("ancestral" %in% class(x)))
17       stop("object \"phy\" is not of class \"ancestral\"")
18   states <- rbind(x$node.character, x$tip.character)
19   cols <- col.fun(n.col)
20   if(ask) {
21     op <- par(ask = TRUE)
22     on.exit(par(op))
23   }
24   for(state in which) {
25     a <- states[x$edge[,2],state]
26     b <- round((n.col-1)*(a-min(a))/(max(a)-min(a)))+1
27     if(plot.node.values) {
28       x$node.label <- x$node.character[,state]
29       plot.phylo(x, edge.color=cols[b], show.node.label=TRUE, sub=state, ...)
30     } else {
31       plot.phylo(x, edge.color=cols[b], sub=state, ...)
32     }
33   }
34 }