From the help found here I\'ve managed to create this multiplot panel:
with the follow
If I understand correctly what you want to do, probably you can use +opts(title = XXX)
:
p1 <- ggplot(mtcars, aes(factor(cyl))) + geom_bar()
p2 <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
p3 <- p2 + geom_line()
pushViewport(viewport(layout = grid.layout(2, 2)))
print(p1 + opts(title = "bar"),
vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(p2 + opts(title = "point"),
vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
print(p3 + opts(title = "point and line"),
vp = viewport(layout.pos.row = 2, layout.pos.col = 1:2))
UPDATED
here is an example:
pushViewport(viewport(layout = grid.layout(3, 2, heights = unit(c(1, 4, 4), "null"))))
grid.text("title of this panel", vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2))
print(p1, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
print(p2, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
print(p3, vp = viewport(layout.pos.row = 3, layout.pos.col = 1:2))
what you need to do is:
library(gridExtra)
p <- ggplot()
grid.arrange(p,p,p,p,p, top = "Title",
layout_matrix = matrix(c(1,2,3,4,5,5), ncol=2, byrow=TRUE))