Skip to content

Instantly share code, notes, and snippets.

@johnDorian
Created January 12, 2015 09:26
Show Gist options
  • Save johnDorian/0fb33ecd01a21f869c94 to your computer and use it in GitHub Desktop.
Save johnDorian/0fb33ecd01a21f869c94 to your computer and use it in GitHub Desktop.
Using cbind and rbind for ggplot plots
# load the libraries
library(ggplot2)
library(gtable)
library(gridExtra)
# Create the plots
p1 <- ggplot() + geom_point(aes(1,1))
p2 <- ggplot() + geom_point(aes(2,2))
p3 <- ggplot() + geom_point(aes(3,3))
p4 <- ggplot() + geom_point(aes(4,4))
# Firstly create two columns (the first and second column)
row1 <- rbind(ggplotGrob(p1), ggplotGrob(p2), size = "last")
row2 <- rbind(ggplotGrob(p3), ggplotGrob(p4), size = "last")
# Combine the two coloumns to create a matrix
matrix_plots <- arrangeGrob(cbind(row1, row2, size = "last"))
# Plot the plots up.
matrix_plots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment