Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

to display two heatmaps in same pdf side by side in R

Tags:

r

pdf

png

heatmap

i am trying to display two or more heatmaps side by side in the same png or pdf . The layout or mfcol is not working in the case. Can someone please help me out with this.

like image 693
Ankita Kumari Avatar asked Feb 27 '13 14:02

Ankita Kumari


1 Answers

Here's one option using the recently introduced gridGraphics package,

enter image description here

library(gridGraphics)
library(grid)
heatmap(as.matrix(mtcars))

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

g <- grab_grob()
grid.newpage()

# library(gridExtra)
# grid.arrange(g,g, ncol=2, clip=TRUE)

lay <- grid.layout(nrow = 1, ncol=2)
pushViewport(viewport(layout = lay))
grid.draw(editGrob(g, vp=viewport(layout.pos.row = 1, 
                                  layout.pos.col = 1, clip=TRUE)))
grid.draw(editGrob(g, vp=viewport(layout.pos.row = 1, 
                                  layout.pos.col = 2, clip=TRUE)))
upViewport(1)
like image 192
baptiste Avatar answered Nov 04 '22 02:11

baptiste