Hi,
does anyone know of a package/hack to draw multipanel heatmaps in R?
Thanks
Hi,
does anyone know of a package/hack to draw multipanel heatmaps in R?
Thanks
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.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Hi lkmklsmn.
What do you mean by multipanel heatmaps? I generally use gplots' heatmap.2.
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.
Could you link to an example/picture of a multipanel heatmap?
For example fig3 from this paper: http://www.nature.com/nm/journal/vaop/ncurrent/full/nm.3385.html
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