Multi-Panel Heatmaps In R
1
2
Entering edit mode
11.1 years ago
lkmklsmn ▴ 980

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

Thanks

r heatmap • 20k views
ADD COMMENT
2
Entering edit mode

Hi lkmklsmn.

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

  library("gplots")
  ?heatmap.2
ADD REPLY
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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
ADD REPLY
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

ADD REPLY
9
Entering edit mode
11.1 years ago
seidel 11k

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.

ADD COMMENT
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!

ADD REPLY

Login before adding your answer.

Traffic: 1846 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6