Monday, June 3, 2013

plotSimmap(...,type="phylogram") now compatible with nodelabels() in ape

I have just posted a new version of the phytools function plotSimmap (and a new phytools package version, phytools 0.2-82) that can be compatible with the ape functions nodelabels, edgelabels, and tiplabels. This is accomplished by setting the environmental variable "lastplot.phylo" in the environment .PlotEnvPhylo following the ape convention. This environmental variable is a list containing all the information used by nodelabels and similar to identify the location of nodes in the current plotting window.

This is a little experimental - but let's try it out:

> # tree is a stochastic map for the anole
> # ecomorph tree
> plotSimmap(tree,pts=FALSE,lwd=3,fsize=0.7,setEnv=TRUE)
no colors provided. using the following legend:
      CG        GB        TC        TG        Tr        TW
  "black"    "red"  "green3"    "blue"    "cyan" "magenta"
setEnv=TRUE is experimental. please be patient with bugs
> nodelabels(cex=0.7)

We can also do leftward facing trees:

> plotSimmap(tree,pts=FALSE,lwd=3,fsize=0.7,setEnv=TRUE, direction="leftwards")
no colors provided. using the following legend:
      CG        GB        TC        TG        Tr        TW
  "black"    "red"  "green3"    "blue"    "cyan" "magenta"
setEnv=TRUE is experimental. please be patient with bugs
> nodelabels(cex=0.7)

One handy use of this might be to plot the posterior probabilities of each node as a pie chart on top of one example stochastic map. (I coerced nodelabels into doing that here, but this is much neater.) For example:

> # trees is 100 stochastically mapped trees
> # get the posterior probs from our sample
> PP<-describe.simmap(trees,message=FALSE)$ace
> # let's leave space for a legend
>; par(mar=rep(0.1,4))
> par(usr=c(-0.04,1.04,-5,1.04*length(tree$tip.label)))
> # set colors
> cols<-setNames(palette()[1:6],sort(unique(getStates(tree,"tips"))))
> # plot
> plotSimmap(tree,cols,lwd=2,pts=FALSE,add=TRUE,fsize=0.7, setEnv=TRUE)
setEnv=TRUE is experimental. please be patient with bugs
> nodelabels(pie=PP,piecol=palette()[1:6],cex=0.6)
> add.simmap.legend(colors=cols,vertical=FALSE)
Click where you want to draw the legend
Click for larger version.

That's pretty cool, I think.


  1. NIce work Liam, I was just struggling with this problem and am delighted that you've provided a solution.

    1. Glad to hear it, Rich. Just did this today and I've only tested it in limited circumstances, so please let me know if you find any problems. Only works for type="phylogram" right now.

  2. I have a built tree (with two methods MrBayes and ML supported by both bayesian posterior probabilities and ML bootsrap)of N sequences.I was wondered whether you can advice me a such statistical method that can be employed to correlate two kinds of external variables, quantitative continuous and qualitative discrete to my tree sequences (or tips). Is the correlation does require a reconstruction of ancestral traits of internal nodes? what is the most adequate statistical method that can be used to test the independence among these continuous and /or discrete variables for the entire tree at first time and foe each clade (mono/parphyletic) at second time. Are the bootstrap values (in case of ML) , posterior probabilities (in case of Bayes) and the branch lengths (in both both) should be specified as prior to answer my question? the inferred sequences in phylogeny are dependent (is an evidence looking homology of sequence alignment), but what is still peculiar for my understanding, is how to test the dependence among external related variables (discrete or continuous) over time?


    PhD in evolutionary biology