0

I am drawing two heatmaps using heatmap.2 separately with different number of rows. Is there any way to set the output of the plots so that the actual cell size is exactly the same between two heatmaps?

library(gplots)
data(mtcars)
x<-as.matrix(mtcars)
###  this heatmap has 32 rows
heatmap.2(x,key=F)


x1<-x[1:10,]
###  this heatmap has 10 rows
heatmap.2(x1,key=F)
TARehman
  • 6,659
  • 3
  • 33
  • 60
Lene
  • 45
  • 7
  • When you say cell size, do you mean row height? – TARehman Sep 19 '14 at 16:09
  • @TARehman yes, I want the height for each row and the width for each column are the same in the output plots – Lene Sep 19 '14 at 16:11
  • if you want to try with [ggplot2](http://stackoverflow.com/questions/20638294/geom-tile-and-facet-grid-facet-wrap-for-same-height-of-tiles/20639481#20639481) – baptiste Sep 19 '14 at 16:16

1 Answers1

0

This can be done, albeit in a something of a kludgy way, by using the lmat, lhei, and lwid arguments of heatmap.2. This arguments get passed to layout and lay out the various parts of the image.

library(gplots)
data(mtcars)
x <- as.matrix(mtcars)
###  this heatmap has 32 rows
heatmap.2(x = x,
          key = F,
          lmat = matrix(c(4,2,3,1),
                        nrow=2,
                        ncol=2),
          lhei = c(0.1,0.9),
          lwid = c(0.3,0.7))

As you can see, the matrix argument gives a matrix that looks like:

     [,1] [,2]
[1,]    4    3
[2,]    2    1

The heatmap is the first thing plotted, followed by the row and then the column dendrogram. The arguments to lhei and lwid give the relative size of each of the layout column and rows described in lmat. With some creativity, you could lay out the panels to allow you to move things up and down as you saw fit. As a proof of concept, I just did the following, which scales lhei by 10/32.

x1<-x[1:10,]
###  this heatmap has 10 rows
heatmap.2(x = x1,
          key = F,
          lmat = matrix(c(4,2,3,1),
                        nrow=2,
                        ncol=2),
          lhei = c(1-0.9*(10/32),0.9*(10/32)),
          lwid = c(0.3,0.7))

Before: Larger Heatmap

After: Smaller Heatmap

TARehman
  • 6,659
  • 3
  • 33
  • 60
  • That's cool! Thank you very much. BTW, do you have any ideas how to put the row labels to the left side and dendrogram to the right side? – Lene Sep 19 '14 at 18:33
  • Not sure about the row labels, but there were options that looked like they might assist. For the dendrogram, you could just alter the matrix to put 2 before 1 on that row, but you'd need to figure out how to get it to go right to left. – TARehman Sep 19 '14 at 18:40