heatmap with colours in R

888 views
Skip to first unread message

FranciscoC

unread,
Jun 29, 2012, 7:38:08 AM6/29/12
to qiime...@googlegroups.com
Hi qiime users,

I´m trying to build a heatmap of my OTU table. I have sucessfully use the make_otu_heatmap function in qiime, wich generated a nice heatmap in black and white. However, I want to include some colors and a dendogram. I believe that the best way to do this is with R, however I´m not very skill with R. Can anyone recommend some function to do this with R, and some script?

Thanks!

Kyle Bittinger

unread,
Jun 29, 2012, 9:35:24 AM6/29/12
to qiime...@googlegroups.com
Paul McMurdie's phyloseq package has utilities for importing BIOM
files into R. It includes a function to create a heatmap from the
resultant object.

https://github.com/joey711/phyloseq

I don't think the phyloseq heatmaps have dendrograms. To make a
heatmap with dendrograms, I would first try to import your data using
Paul's library, then extract a matrix of OTU counts (I don't know how
to do this off the top of my head, but it should be possible). Once
you have this, you can provide it as input to R's built-in heatmap
function. The pheatmap package augments this function and adds many
conveniences; this may be something useful to check out, too.

--Kyle

joey711

unread,
Jul 3, 2012, 12:42:03 PM7/3/12
to qiime...@googlegroups.com

First, I haven't used the pheatmap package, but if Kyle recommends it, it is probably good. To extract the matrix of OTU counts after importing from BIOM, the accessor function to use is:


otuTable(x)


Where `x` is your imported object. `x` will be a class that inherits directly from the standard "matrix" class, so it might work directly in whatever function. For example, the base heatmap function in R would work: 


heatmap(otuTable(x))


If some other function is not working because it has hard-coded the expected class (or some other class issue), you can coerce it using:


as(otuTable(x), "matrix")


Secondly, the tools for plotting heatmap(s) of OTU abundances (or some transformation thereof) is easy to do with the `plot_heatmap` function in phyloseq. More explanation on the approach, and examples with code/results is provided on the following wiki page:


https://github.com/joey711/phyloseq/wiki/plot_heatmap


Kyle is right that it does not include dendrograms, but that is by design. The `plot_heatmap` function uses the same approach as in the NeatMap package, using ordination methods to organize the heatmap, rather than hierarchical clustering. The authors of NeatMap explain this in more detail in the following article:


http://www.biomedcentral.com/1471-2105/11/45


Basically, the dendrogram/tree representation of distances is too flexible for representing the a complex heatmap, and can easily lead to either confusing or misleading ordering of the columns/rows. 

Reply all
Reply to author
Forward
0 new messages