Monday, August 6, 2012

3D phylomorphospace plotting function

I just posted a preliminary version of a three-dimensional phylomorphospace function that uses the 3D visualization package 'rgl'. The visualization below is a video created using the function spin3d and movie3d. Phylomorphospace is just a projection of a phylogeny into (in this case) a three dimensional phenotype space. Leaves on the graph are the phenotypes of tip species. Lines connect tips to their common ancestors, reconstructed in morphospace using ML ancestral character estimation (phytools function anc.ML).

The function is relatively simple. I just create a set of matrices of dimensions equal to the matrix tree$edge. Then I fill the matrices using the values for tip species and the values for internal nodes. Next, I plot all the values for tip and internal nodes. I add the edges using the matrices described above. Finally, I plot tip labels - crudely adjusting them away from the tip vertices depending on the three dimensional position of the tip.

Source for the function is here. The function depends on 'rgl', not currently a dependency of phytools, so to run it do the following:

> install.packages("rgl")
> library(rgl)
> library(phytools)
> source("phylomorphospace3d.R")
> tree<-pbtree(n=10)
> X<-cbind(fastBM(tree),fastBM(tree),fastBM(tree))
> phylomorphospace(tree,X)

No comments:

Post a Comment

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