Thursday, June 6, 2013

Even simpler phylomorphospace

As I mentioned yesterday, I'm working a book chapter on PCM visualization methods. A very small section of that chapter gives an introduction to programming such methods in R. To that end I described a simplified tree plotting function. Here is code for a simplified phylomorphospace plotting function. It needs phytools (and dependencies) and calibrate.

  # get the x & y coordinates of all the tips & nodes
  # plot tips
  # plot nodes
  # plot lines
  apply(tree$edge,1,function(edge,x,y) lines(x[edge],
  # add tip labels (requires 'calibrate')
(Just seven lines of code, excluding comments.)

Let's see how it works:

> require(phytools)
Loading required package: phytools
> require(calibrate)
Loading required package: calibrate
> source("simplePhylomorphospace.R")
> tree<-pbtree(n=30)
> x<-fastBM(tree)
> y<-fastBM(tree)
> simplePhylomorphospace(tree,x,y)

No comments:

Post a Comment

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