Thursday, November 27, 2014

Bug fix in plot.contMap / plot.densityMap

A few months ago Eliot Miller reported a strange bug in contMap in which sometimes weird, white (and thus nearly invisible on a white background) text was appearing on certain parts of the plot.

For example:

library(phytools)
## Loading required package: ape
## Loading required package: maps
packageVersion("phytools")
## [1] '0.4.36'
set.seed(1)
tree<-pbtree(n=26,scale=1)
## realistic tip labels
tree$tip.label<-paste(LETTERS[26:1],"._",sep="",replicate(26,paste(sample(letters,sample(3:12,1)),collapse="")))
x<-fastBM(tree)
obj<-contMap(tree,x,outline=TRUE)

plot of chunk unnamed-chunk-1

The white text is what appears to cause the lines close to the base of the tree to be interrupted.

Well, this bug isn't quite as mysterious as it might seem at first blush. This is because to plot the outline of the phylogeny and then the contMap I use two calls to the phytools function plotSimmap internally; however to avoid plotting the labels twice I first set par(col="white"), plot the outline tree, and then set par(col="black") and plot the "contMap".

Why the text is showing up in the wrong place, on the other hand, beats me - although I'll bet it has something to do with how I am computing the label offset. Oh well. A quick fix that I have applied in the latest non-CRAN phytools version is to use par(col="transparent") instead of par(col="white"). Hopefully all plotting devices support transparency.

Here's how it works:

detach("package:phytools",unload=TRUE)
install.packages("phytools_0.4-38.tar.gz",type="source")
## Installing package into 'C:/Users/Liam/Documents/R/win-library/3.1'
## (as 'lib' is unspecified)
## inferring 'repos = NULL' from 'pkgs'
library(phytools)
packageVersion("phytools")
## [1] '0.4.38'
plot(obj)

plot of chunk unnamed-chunk-2

OK, problem solved. I'm a little concerned that transparency will not be supported by all plotting devices, but hopefully this is a temporary fix & I can figure out the real problem.

That's it. Happy Thanksgiving.

No comments:

Post a Comment