This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Multiple Heatmap plot in one canvas with mfrow?

Hi All,

Any solution to plot multiple heatmap in one page in R (heatmap.2 in gplots)? par(mfrow=c(2,2)) don't work. It will plot the heatmap in separate pages.

Thanks.

heatmap mfrow

1 answer

I find the solution eventually, Anyway, share with others, hope it is helpful in your routine analysis. Also, I found gridGraphics and grid is very useful for complicated figure preparation.

library(gridGraphics)
library(grid)

grab_grob <- function(){
  grid.echo()
  grid.grab()
}

data<-read.table("heatmap.input.matrix.data.txt")

library(gplots)
gl <- lapply(1:ncol(data), function(i){
  heatmap.2(data.matrix(data[[i]]))
  grab_grob()
})

grid.newpage()
library(gridExtra)
grid.arrange(grobs=gl, ncol=5, clip=TRUE)

Log in to answer this question.