Thursday, July 11, 2013

Small update to contMap and densityMap to suppress plotting

The phytools functions densityMap and contMap invisibly return objects of class "densityMap" and "contMap", respectively. However there was previously no way to suppress plotting - which might be desired if (say) the density map was being produced to project onto a phylomorphospace plot. Today I added the capacity to turn off plotting to both functions and they are included in the latest phytools build (phytools 0.2-05).

Here's a demo, using simulated data & densityMap:

> # load phytools
> require(phytools)
Loading required package: phytools
> packageVersion("phytools")
[1] ‘0.2.95’
> # simulate data for a discrete character
> Q<-matrix(c(-1,1,1,-1),2,2)
> rownames(Q)<-colnames(Q)<-0:1
> tree<-sim.history(pbtree(n=40,scale=1),Q)
> # simulate data for two continuous characters
> # with a rate matrix that varies by state
> R<-setNames(list(matrix(c(1,0,0,1),2,2),
  matrix(c(5,4,4,5),2,2)),0:1)
> X<-sim.corrs(tree,R)
> # conduct stochastic map
> trees<-make.simmap(tree,tree$states,nsim=100)
make.simmap is sampling character histories conditioned on the transition matrix
Q =
           0          1
0 -0.7416182  0.7416182
1  0.7416182 -0.7416182
(estimated using likelihood);
and (mean) root node prior probabilities
pi =
  0  1
0.5 0.5
Done.
> # create a density map but suppress plot
> XX<-densityMap(trees,plot=FALSE)
sorry - this might take a while; please be patient
> # project density map onto phylomorphospace
> par(mar=c(5.1,4.1,2.1,2.1))
> phylomorphospace(XX$tree,X,colors=XX$cols, node.by.map=TRUE,lwd=3,xlab="trait 1",ylab="trait 2")
(Click here for full size.)

No comments:

Post a Comment