Jonathan Olmsted

ggplot Snippet

| Comments

I had no idea where on my computer to save the following R snippet to use with ggplot. And, there is no chance I’d remember it because I’ve only used it a handful of times (and rarely “combine” figures within R). Hopefully, this will be a useful storage location.

Below, the objects “A” and “B” must otherwise exist as the output of a ggplot(data) + ... expression.

ggplot Snippet
1
2
3
4
5
6
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
vplayout <- function(x, y)
viewport(layout.pos.row = x, layout.pos.col = y)
print(A, vp = vplayout(1, 1))
print(B, vp = vplayout(1, 2))