drawing heatmap with dendrogram along with sample labels

11,583

Try the heatmap.2 function from the gplots package, which has arguments RowSideColors and ColSideColors to create side bars.

If this doesn't meet your needs, the heatmap.plus package allows further customisation, such as multiple colour side bars.

Share:
11,583

Related videos on Youtube

Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    Using the heatmap function of made4, I made this heatmap dendrogram from the example file:

    data(khan)
    heatplot(khan$train[1:30,], lowcol="blue", highcol="red")
    

    How can I add a panel of labels for the samples on the edges of the heatmap, like in this figure?

    enter image description here

    The labels in this case are the squares that are adjacent to the heatmap first col and top row, used to denote a label for each sample so that one can see if the labels correspond with the clustering shown by the heatmap/dendrogram. In this particular plot they chose to make those labels correspond exactly to the colors of the dendrogram clusters but it doesn't have to be this way, I'm looking for way to just add a generic column and row of labels to the samples which might not correspond to the clustering resulting from applying a particular threshold of the dendrogram.

    The heatmap function and the khan data is from made4:

    require(made4)
    

    see http://www.bioinf.ucd.ie/people/aedin/R/pages/made4/html/heatplot.html

    I'm happy to use alternatives to heatplot that can draw the same thing, a heatmap with two dendrograms along the side based on hierarchical clustering. heatplot is just an example.

    When I try heatmap.2 like @HeatherTurner suggested I get this image (not sure how to turn off row/column labels on matrix to make it less clustered):

    enter image description here

    The heatmap looks corrupted. Here's code that reproduces this with a small data set:

    require(gplots)
    data(khan)
    heatmap.2(as.matrix(khan$train[1:30,])
    

    which generates this: enter image description here

    What is causing these corrupted looking heatmaps?

    update: apologies, I think the heatmaps are not corrupted it's just the trace column is on which causes the cyan line to be drawn through heatmap. setting trace=none resolves the issue.

    ps it looks like heatmap has RowSideCols, which might be same argument?

    • joran
      joran over 10 years
      You will probably have to explain where the function heatplot is from, and possibly where the khan data came from as well. (I can't seem to find either.)
    • Admin
      Admin over 10 years
      @joran: it's made4, added clarification, thanks
    • joran
      joran over 10 years
      Ah, that explains it. Not on CRAN.
    • Admin
      Admin over 10 years
      @joran: I'm happy to use some thing other than heatplot if it can draw the same thing, that's just the easiest thing I found
    • baptiste
      baptiste over 10 years
      if you want to use ggplot2, maybe this helps (I never know what those rooty things mean)
    • Admin
      Admin over 10 years
      @baptiste: always prefer ggplot! thanks. which rooty things?
  • Admin
    Admin over 10 years
    see my edits. I think heatmap has the same argument you refer to from gplots and heatmap.2 does not work for me for some reason - it gives a messed up image