I’m using R to create a heatmap from a matrix using heatmap.2 – and i want to group these images into one big image – What i usually use to achieve this is layout() – but this doesn’t work, as heatmap.2 uses layout, and apparently layout does not work recursively.
Does anyone have any suggestions on how to group together 2 images without layout, or how to make layout support recursive calls?
mat = matrix(nrow=3,nrow=3,1:9)
layout(matrix(nrow=2,ncol=1))
heatmap.2(mat) ## overrides the layout and produces only one plot that takes whole screen
heatmap.2(mat) ## still only one image
thanks.
What follows is a hack that is almost certainly not a perfect solution, but it may get you started.
Create your own version of the
heatmap.2function calledhm3. In the code forhm3, comment out all the lines between:and the
layoutcall:it’s a big chunk of code, maybe 30 lines. Now the following code produces two heat maps with dendrograms and keys side by side:
Clearly, this will require considerable tweaks to make it look nice (and a larger plotting area; I’ve squished everything to be a reasonable size to post here).
This is entirely untested. It is likely that using any of the options in the
hm3function that control the appearance of the plot will cause things to go slightly haywire. But this may be a good starting point for your own experimentation to address those issues.