Multi-Panel Heatmaps In R
1
2
Entering edit mode
8.0 years ago
lkmklsmn ▴ 950

Hi,
does anyone know of a package/hack to draw multipanel heatmaps in R?

Thanks

r heatmap • 17k views
2
Entering edit mode

Hi lkmklsmn.

What do you mean by multipanel heatmaps? I generally use gplots' heatmap.2.

  library("gplots")
?heatmap.2

0
Entering edit mode

That what I ended up using, but I would rather make separate heatmaps. I know you can add 'rowsep' or 'colsep', but they draw over the heatmap and dont actually move the two heatmaps away from each other.

0
Entering edit mode

Could you link to an example/picture of a multipanel heatmap?

0
Entering edit mode
2
Entering edit mode

I would guess that they made 4 different heatmaps keeping the axis consistent then trimmed off the axis/labels and then put it together in photoshop

9
Entering edit mode
8.0 years ago
seidel 8.5k

One way to draw several heat maps together would be to use the layout() function along with image(). Layout (type ?layout for help) is a way to divide the graphics device up for arranging plots. The image() function is a generic way of drawing heat map grids. Thus you could use the regular heatmap() function to easily get your row and column orderings for your heat maps, but then redraw them using layout() and image(). For example:

# for an example heat map
some_random_data <- matrix(rnorm(100), nrow=10,ncol=10)
hm1 <- heatmap(some_random_data)

# hm1$rowInd now contains the row ordering of your data in the heat map image  If you had 4 such heat maps that you want to create in an arrangement, use layout() to divide up the graphics device. The first argument is a matrix reflecting the order to draw the plots, the second argument has to do with the widths and heights of the rows and columns. It's a bit confusing, but read the documentation and experiment: # create a layout to draw 4 heatmaps, 2 will be big and 2 will be small nf <- layout(matrix(c(1,2,3,4),2,2, byrow=T), widths=c(2,2), heights=c(3,1), respect=T) # check how the layout looks layout.show(nf) # now draw 4 heat maps image(matrix(rnorm(100),10,10)) image(matrix(rnorm(100),10,10)) image(matrix(rnorm(50),10,5)) image(matrix(rnorm(50),10,5))  That's the basic idea. It looks ugly at first because of the default margins etc., but then you can start cleaning it up: layout(matrix(c(1,2,3,4),2,2, byrow=T), widths=c(2,2), heights=c(3,1), respect=T) # adjust the margins par(mar=c(3,2,2,1)) # turn off the axes image(matrix(rnorm(100),10,10), axes=FALSE) image(matrix(rnorm(100),10,10), axes=FALSE) image(matrix(rnorm(50),10,5), axes=FALSE) image(matrix(rnorm(50),10,5), axes=FALSE)  The last caveat is that when you give image() a matrix of numbers, it transposes it. Thus to draw your heat map the way you see it in heatmap(), you'd have to do something like the following: image(t(some_random_data)[hm1$rowInd,])


which transposes your data, then puts the rows in the heatmap order, then image() draws it. You can add labels, and axes, and titles, and make legends, etc. all using typical R plotting stuff. Igt just takes a while to figure it all out.

0
Entering edit mode

Though it is a bit late (just ~3y after this was posted), I still want to say thanks. This is really helpful!