Wednesday, December 19, 2012

Specifying pie colors in ancThresh & plotThresh

A phytools user contacted me to express difficulty in controlling pie colors at nodes using the new phytools functions for ancestral character estimation under the threshold model, ancThresh and plotThresh. This is done using the argument piecol, set to a vector with the states for the discrete trait as names, and the desired colors as values (in any format acceptable by R, e.g., here).

Here's a quick demo. I assume that we've already run the MCMC, and mcmc is the object returned by ancThresh. Data are in X:
> cols
   not     mod    high
"green"  "blue"   "red"
> plotThresh(tree,X,mcmc,piecol=cols,tipcol="estimated", label.offset=0.01)

Note that label.offset is on the scale of your phylogeny, so will have to be varied with total tree length. I've been meaning to migrate control of the pie sizes to the user, but have not yet had time to do so. (Plus, I've been sick.)


  1. Hi Liam,

    Is there now a way to change the pie sizes using plotThresh()? I am having a hard time visualizing my 310 tip tree.



    1. Unfortunately, this is not presently an option. It is, however, possibly to plot the posterior probabilities on the tree 'manually' and adjust the node label size that way. An example of this can be seen here.

    2. Thanks for your prompt reply!
      The challenge has been plotting the nodelabels the way that plotThresh(... tipcols="input") does. The probability scores in my n x 4 matrix are unlike other "common" input values (e.g. binary, continuous). If I try:
      > tiplabels(pie = x.matrix, ...)
      I get this error, though I have no negative values in my x.matrix

      Error in floating.pie.asp(XX[i], YY[i], pie[i, ], radius = xrad[i], col = piecol) :
      floating.pie: x values must be non-negative

      I'll keep working at it. Thanks again!