Friday, January 29, 2016

New function for phylogenetic heat map

I just added a preliminary version of a new function to phytools for plotting a “phylogenetic heat map.” This visualization is roughly akin to the R stats function heatmap: although instead of plotting a dendrogram next to the plotted data, it plots an input tree. This was something requested of me by a colleague Nate Swenson some time ago, but unfortunately I didn't get around to trying it until today.

Here's a quick demo of how it works. To follow, one would have to install the latest version of phytools from GitHub:

library(devtools)
install_github("liamrevell/phytools")

Now, let's try it:

library(phytools)
packageVersion("phytools")
## [1] '0.5.13'
## simulate a tree & some data
tree<-pbtree(n=26,tip.label=LETTERS[26:1])
X<-fastBM(tree,nsim=12)
phylo.heatmap(tree,X)

plot of chunk unnamed-chunk-2

A few different attributes can be customized about the plot, and I'm open to making it more flexible if there is interest. For instance, it is quite straitforward to change the palette:

## terrain colors
phylo.heatmap(tree,X,colors=terrain.colors(20))

plot of chunk unnamed-chunk-3

## interpolated blue->red
colors<-colorRampPalette(colors=c("blue","red"))(100)
phylo.heatmap(tree,X,colors=colors)

plot of chunk unnamed-chunk-3

It also works & looks pretty good for non-ultrametric trees:

tree<-rtree(n=40)
X<-fastBM(tree,nsim=20)
colnames(X)<-paste("trait",1:20)
phylo.heatmap(tree,X,fsize=c(0.8,0.8,1))

plot of chunk unnamed-chunk-4

That's it for now.

2 comments:

  1. Hola Liam,

    Excelente función, muy útil. Pero quería preguntarte ¿es posible cambiar el grosor de las ramas en el árbol filogenetico (like lwd or edge.width). ?
    Lo he intentado, pero no he podido hacerlo.

    Saludos,

    Jaiber

    ReplyDelete
    Replies
    1. Hola Jaiber.

      Acabó de añadir esta capacidad: http://blog.phytools.org/2016/02/a-bit-more-user-control-for-phyloheatmap.html. Desafortunadamente, la función usada al interior de phylo.heatmap, no es tan compleja que otras en phytools, así que este update no te da un montón de opciones adicionales, pero te puedes a menos controlar el grosor de las ramas visualizadas.

      - Liam

      Delete