I recently
reported
a bug in dotTree
that is caused (but for reasons beyond my
comprehension) by updating the package
plotrix
to it's most recently version.
The bug basically causes all the circles plotted at the tips of the tree to merge into a huge smear. Here's what I mean, using some simulated data:
library(phytools)
dotTree(utree,xu)
## Warning in cos(angles) * radius[circle] + x: longer object length is not a
## multiple of shorter object length
or, for multiple characters:
dotTree(utree,Xu)
## Warning in cos(angles) * radius[circle] + x: longer object length is not a
## multiple of shorter object length
Woah! Here is what a discrete character looks like:
dotTree(tree,y)
## Warning in cos(angles) * radius[circle] + x: longer object length is not a
## multiple of shorter object length
Obviously, this is no good - and the
recommendation
(such as it was) that I have been giving is to just not update plotrix, or
to roll it back if you've already updated the package. What I did today,
though, was
“fix”
dotTree
instead (although I'd contend it was never broken) to
work around this feature.
The way I did it was by using mapply
to call the plotrix
function draw.circle
multiply across the elements of several
vectors, instead of all at once (which previously worked just fine).
Here's a quick demo. Not that reading the source in & setting
phylogram<-phytools:::phylogram
should not be necessary if you
merely update phytools from GitHub:
library(plotrix) ## get plotrix into name space
phylogram<-phytools:::phylogram
source("https://raw.githubusercontent.com/liamrevell/phytools/master/R/dotTree.R")
dotTree(utree,xu)
dotTree(utree,Xu)
dotTree(tree,x)
dotTree(tree,y)
On the very last plot, it looks like the legend is also messed up. This must
be because add.simmap.legend
also uses draw.circle
from plotrix internally. I'll have to check this out.
The data for this demo were simulated as follows:
utree<-pbtree(n=26)
utree$tip.label<-LETTERS[26:1]
xu<-fastBM(utree)
Xu<-fastBM(utree,n=6)
tree<-rtree(n=26)
tree$tip.label<-LETTERS[26:1]
x<-fastBM(tree)
y<-sim.history(tree,matrix(c(-1,1,1,-1),2,2))$states
Already fixed add.simmap.legend so dotTree for data.type="discrete" should be good.
ReplyDelete