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.

2 comments:

  1. Hi Liam
    I wonder if there is a way to remove the outline of the pies i.e. remove the black borders of the pies

    ReplyDelete
    Replies
    1. You can do:
      `par(fg="transparent")`
      add the node labels, and then run:
      `par(fg="black")`

      All the best, Liam

      Delete

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.