1 ## plot.ancestral.R (2005-12-04)
3 ## Plotting Ancestral Characters on a Tree
5 ## Copyright 2005 Julien Dutheil
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
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(),
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)
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, ...)
31 plot.phylo(x, edge.color=cols[b], sub=state, ...)