Wednesday, June 5, 2013

Simple tree plotter

As I mentioned in a prior post I am writing a book chapter on visualization for phylogenetic comparative biology. As I component of this, I discuss the basics of plotting a couple of different types of phylogenetic trees, including some instruction on programming these methods.

For one component of this I wrote a simplified tree plotting function in R. This is what it looks like. Excluding annotation, the function code is less than 20 lines:

  # reorder cladewise to assign tip positions
  # reorder pruningwise for post-order traversal
  # compute vertical position of each edge
  for(i in 1:length(nn)){
  # compute start & end points of each edge
  # open & size a new plot; par(mar=rep(0.1,4))
  # plot horizontal edges
  for(i in 1:nrow(X))
  # plot vertical relationships
  for(i in 1:tree$Nnode+n)
  # plot tip labels
  for(i in 1:n)

Try it out:

> require(phytools)
Loading required package: phytools
> tree<-pbtree(b=1,d=0.2,n=30)
> simpleTreePlot(tree)

Any suggestions?

No comments:

Post a Comment

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