Friday, February 9, 2018

Small fix for 'static' 3D phylomorphospace plotting

I recently pushed a tiny update to the phytools function phylomorphospace3d (also used internally by fancyTree(...,type="traitgram3d") for method="static". This method uses the package scatterplot3d to simulate a three-dimensional projection of the tree into morphospace (or, in the case of "traitgram3d", a projection of the tree into a three-dimensional space defined by two morphological traits and time since the root). This update is in response to user reports that with some tree & trait scale combinations the space of the plot can appear extremely stretched or flattened.

Let's see how the method works with some simulated data:

library(phytools)
tree<-pbtree(n=30,scale=100)
vcv<-diag(c(0.01,1.0,10.0))
X<-sim.corrs(tree,vcv)
X
##            [,1]       [,2]       [,3]
## t8  -1.83242085  6.7210134  -8.664145
## t12 -1.15607024  6.9973451 -13.088127
## t24 -1.20569729  9.7727382 -15.425783
## t25 -1.10653325  9.7555249 -16.819261
## t5  -1.48039787 10.4446110 -23.209189
## t27 -1.31163205 19.3352026 -38.736942
## t28 -1.42809690 19.8008715 -35.600357
## t26 -1.40833515 20.4864698 -34.721207
## t23 -1.70902492 20.1792875 -38.754384
## t19 -1.68176620  1.4706946 -36.622222
## t20 -2.24323061  1.5492804 -37.739377
## t10 -1.19887289  3.7941856 -33.382013
## t11 -1.17648353 12.5826137 -19.722484
## t13  0.13900173 -1.1595256 -14.034705
## t21 -0.03889558  7.5848620 -36.576738
## t22  0.37449846 -0.6209873 -30.928140
## t14  0.53322638  4.2027966 -39.983553
## t9   0.24085843  2.3645035 -63.081849
## t29 -1.48428219  4.8378941 -14.046100
## t30 -1.47328983  5.4626160 -14.496791
## t2  -0.88728348  7.3949668 -24.898061
## t1  -1.84599443  5.6916087 -56.213488
## t4  -0.68412064  3.6165038  13.830777
## t15 -1.95272282 -0.3652135  49.609482
## t16 -1.38347887  2.9467029  67.053588
## t6  -0.66320389 -0.4777789  14.183655
## t7  -2.03189993  1.1912653  67.740006
## t17 -1.71885755  4.9178237  40.701543
## t18 -1.32472518  8.6595917  33.794385
## t3  -1.72539854 -1.0492751  31.683496
phylomorphospace3d(tree,X,method="static")

plot of chunk unnamed-chunk-2

Now a 3D traitgram with the 1st & 3rd dimensions:

fancyTree(tree,X=X[,c(1,3)],type="traitgram3d",method="static")
## Warning in traitgram3d(tree, ..., control = control): anc.ML may not have
## converged; consider increasing maxit.

plot of chunk unnamed-chunk-3

Neat.

To get this fix users can update in a clean R session from GitHub as follows:

library(devtools)
install_github("liamrevell/phytools")

Another related method is also in fancyTree:

fancyTree(tree,X=X,type="scattergram")
## Computing multidimensional phylogenetic scatterplot matrix...

plot of chunk unnamed-chunk-5

That's it.

No comments:

Post a Comment

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