I'm attempting to plate two plots in the same .jpg using arrangeGrob(). I've only just started learning about grids and grobs and I think I know what the problem is: pheatmap is a grid object and containing grob objects, not allowing me to put it in arrangeGrob. Is this true?
Would I somehow need to put the qplot in a grid and the pheatmap in a grid and then put those grids in a new grid?
library(grid)
library(gridExtra)
library(pheatmap)
library(ggplot2)
hmdat=rbind(c(1,2,3),
c(3,4,5),
c(5,6,7))
hm=pheatmap(hmdat)
qp=qplot(1,1)
lm=rbind(c(1,2,2),
c(1,2,2))
jpeg("plots.jpg")
arrangeGrob(qp,hm, layout_matrix=lm)
dev.off()
The above code snippet runs just fine when using
arrangeGrob(qp,qp, layout_matrix=lm)
arrangeGrob(qp, hm[[4]], layout_matrix=lm)
. The manual page forpheatmap()
clearly states in theValues
section that it returns alist
of components, but it fails to mention component #4, which is thegtable
of the plot. You have to index it specifically since it's not going to trigger R'sprint
method lookup/execution for that object inside the function call. – Augment