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.

6 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
  2. Hi Liam,

    Thanks for your awesome phytools package. Is there a way to merge phylo.heatmap and contMap so that the tree presented in phylo.heatmap is colored as in contMap?

    Luke

    ReplyDelete
  3. Hola Liam
    Estoy haciendo un phylo.heatmap con 6 rasgos y me funciona muy bien, pero en dos especies aparecen lineas cruzadas y no colores. Todas las especies tienen datos así que no es falta de información. A qué se podría deber este problema?
    Gracias

    ReplyDelete
    Replies
    1. Lo mas probable es que existe algun incongruencia entre los nombres de la filogenias y los nombres de las filas en su matriz. Sugiero que los verifique usando la funcion name.check en el paquete geiger. La conozca?

      Un saludo, Liam

      Delete
  4. Hi Liam, I would wish to supress the dots conecting the tips with the names, and instead use all the available space to plot species names with larger size. Also, in order to include family information for large trees, to be able to paint the tree lines with colors by family and supress dots and species names at all. Do you see any easy options for that? Thanks for all this help you provide with plotting phylogenies!

    ReplyDelete

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