Thursday, October 27, 2016

Plotting multiple pie charts at nodes

An R-sig-phylo question asked:

“I have made an ancestral state reconstruction for three discrete traits using the R package "phytools”,and I don't know how to draw the three asr pies on the node in a single plot.“

Although this can get messy, it is possible to do this using the argument adj. For instance:

library(phytools)
plotTree(tree)
nodelabels(pie=p1,adj=c(0.5,0.9),cex=0.5)
nodelabels(pie=p2,adj=c(0.5,0.5),cex=0.5)
nodelabels(pie=p3,adj=c(0.5,0.1),cex=0.5)

plot of chunk unnamed-chunk-1

to arrange vertically. To arrange horizontally, do:

plotTree(tree)
nodelabels(pie=p1,adj=c(0.445,0.5),cex=0.5)
nodelabels(pie=p2,adj=c(0.5,0.5),cex=0.5)
nodelabels(pie=p3,adj=c(0.555,0.5),cex=0.5)

plot of chunk unnamed-chunk-2

The specific values for adj will depend on the scale of the tree & the number of tips.

No comments:

Post a Comment