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)

1 comment:

  1. The simple truth is I like this article, the author's writing was very honest, very clever writing skills.