First edit the print.ggpairs function print.ggpairs that it no longer grid.newpage . For this call
library(GGally) fixInNamespace("print.ggpairs", ns = "GGally")
and make line 32 a comment. Then you can use the grid functions:
library(ggplot2) data(iris) df <- data.frame(y = rnorm(100)) p1 <- ggpairs(iris, colours='Species') p2 <- ggplot(df, aes(x=1:100, y=y)) + geom_line() library(grid) grid.newpage() pushViewport(viewport(layout=grid.layout(1,2))) vp1 <- viewport(layout.pos.col=1, layout.pos.row=1) vp2 <- viewport(layout.pos.col=2, layout.pos.row=1) pushViewport(vp1) p1 popViewport() pushViewport(vp2) plot(p2, vp = vp2) popViewport()

Edit: I sent a function request, and ggally supporter added a parameter to disable grid.newpage , that is, you can do print(p1, gridNewPage = FALSE) now: https://github.com/ggobi/ggally/issues/125
source share