I have a phylogenetic tree and data on two traits, x and y. To present them, I would like to show the phylogenetic relationships while preserving the xy positions in trait space (i.e., convex hulls). I presume this would be done in 3d. How can I do this in R?
-
$\begingroup$ It sounds to me like you might want to plot the minimum spanning tree within each of the clusters (see perhaps the spantree function in the vegan package). $\endgroup$– Andy WCommented Jul 17, 2013 at 18:52
-
$\begingroup$ At the very least, it looks like I could use it as a model a viable 2d alternative, although I don't want a minimum spanning tree for within-clusters representation. I want a between-clusters representation for the protoclust linkage outcome. Maybe, since I only have 6 clusters, I'll cobble together a subset data frame and make creative use of the "lines" command, especially, since in a protocluster solution, the "center" is always a specific leaf node. $\endgroup$– BryanCommented Jul 17, 2013 at 19:37
2 Answers
Once again, I ended up finding my own answer. The package is called "phytools", and the command is "fancyTree". You can visualize a projection of the phylogeny into trait space in 3 dimensions.
tree <- pbtree(n=10,scale=10)
Y <- sim.corrs(tree,vcv=matrix(c(1,0.75,0.75,1),2,2))
fancyTree(tree,type="traitgram3d",X=Y,control=list(spin=FALSE))
-
7$\begingroup$ Here it goes a suggestion to improve your answer: post a reproducible code to build this type of graph and then, maybe, upload the output graph/picture (to show exactly ywhat you were looking for). $\endgroup$ Commented Sep 9, 2013 at 16:37
A 2D solution for simultaneously visualizing position in trait space and phylogenetic relationships is to use plotGMPhyloMorphoSpace
from the geomorph
package. This function shows species positions with respect to the first 2 principal components of the traits you provide it, so you can give it more than just 2 traits and it will plot them in a 2D trait space.
library(geomorph)
tree <- rcoal(n=20)
Y <- sim.corrs(tree,vcv=matrix(c(1,0.5,0.5,1),2,2))
plotGMPhyloMorphoSpace(tree, Y, node.labels=FALSE,
plot.param=list(t.cex=0.75, n.cex=0.5, txt.cex=0.5, lwd=0.5))
As with the 3D plot using fancyTree
, things can get messy and you may want to trim the tree to taxa/clades of interest before plotting.