I realized after creating the three dimensional phylomorphospace function (phylomorphospace3d, described here) that one neat use of this function would be to do three dimensional traitgrams. That is, a projection of the tree into a space defined by time on one axis, and phenotype (in this case) on the other two.
This is relatively easy to do. This is because we've set up phylomorphospace3d to either estimate ancestral states or take them as input. To create a traitgram/phenogram - we just need to first estimate ancestral states for two characters, and then also compute the heights of internal and terminal nodes as our third "trait" (time from the root of the tree).
Both of these tasks are straightforward to accomplish. First, to estimate ancestral nodes for two characters encoded as columns in matrix X, we just do:
> A<-apply(X,2,function(x,tree) anc.ML(tree,x)$ace,tree=tree)
Then, we can compute the heights of internal and terminal nodes and attach them as columns in X and A, respectively.
> A<-cbind(A,nodeHeights(tree)[match(rownames(A)[1:nrow(A)], tree$edge)])
The final step, of course, just names our new trait axis what it is "time" since the root of the tree. With these parts, we can now use the new function phylomorphospace3d to plot our 3D traitgram.
I have built the steps above into the wrapper, fancyTree. To try it, just download the latest versions of the code for fancyTree (here) and phylomorphospace3d (here), load the source, and give it a try. The code below also uses the new simulation function sim.corrs, described here, but not yet a part of phytools.
And here's the result:
Very cool function. Should specifying colours via control= work in fancyTree? For my data it works for phylomorphospace, but not for phylomorphospace3d.ReplyDelete
Unfortunately, this is not yet possible in phylomorphospace3d. I don't think it would be too hard to add, but I just have not done this yet. Sorry! When I add this feature, I will definitely note it in the blog.
Thanks for using phytools. - Liam
I have been using this function and really like it and like Roger would want to be able to change the color of the lines and the label size. Looking forward to being able to do this! Will look amazing in the little movie!
I know it's been a few years since this blog post's been up, but I have a function that does the same thing, which you can colours the branches.ReplyDelete
It's not in any R package yet, but the paper is here: http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0039752#pone-0039752-g006
Cool. I like it! I was going to ask why you didn't cite phytools, but I see your paper & function are several years old. I should've been citing you! I also like how you show the phylomorphospace in two and three (with time) dimensions simultaneously. Thanks for sharing this.Delete