3  Multiple ggplots with patchwork

Published

2025-08-29

The package patchwork (Pedersen (2025)) makes combining ggplots possible.

Example from here.

library(ggplot2)
p1 <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp)) + 
  ggtitle('Plot 1')

p2 <- ggplot(mtcars) + 
  geom_boxplot(aes(gear, disp, group = gear)) + 
  ggtitle('Plot 2')

p3 <- ggplot(mtcars) + 
  geom_point(aes(hp, wt, colour = mpg)) + 
  ggtitle('Plot 3')

p4 <- ggplot(mtcars) + 
  geom_bar(aes(gear)) + 
  facet_wrap(~cyl) + 
  ggtitle('Plot 4')

library(patchwork)

Plots next to each other

p1 + p2

Plots under each other

p1 /p2

All at once

p1 + p2 + p3 + p4