Learn R Programming

⚠️There's a newer version (1.3.0) of this package.Take me there.

patchwork

The goal of patchwork is to make it ridiculously simple to combine separate ggplots into the same graphic. As such it tries to solve the same problem as gridExtra::grid.arrange() and cowplot::plot_grid but using an API that incites exploration and iteration, and scales to arbitrily complex layouts.

Installation

You can install patchwork from github with:

# install.packages("devtools")
devtools::install_github("thomasp85/patchwork")

Basic example

The usage of patchwork is simple: just add plots together!

library(ggplot2)
library(patchwork)

p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))

p1 + p2

patchwork provides rich support for arbitrarily complex layouts with full alignment. As an example, check out this very readable code for nesting three plots on top of a third:

p3 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec))
p4 <- ggplot(mtcars) + geom_bar(aes(carb))

(p1 | p2 | p3) /
      p4

Learn more

patchwork can do so much more. Check out the guides for learning everything there is to know about all the different features:

Code of Conduct

Please note that the patchwork project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('patchwork')

Monthly Downloads

266,358

Version

0.0.1.9000

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Thomas Pedersen

Last Published

September 16th, 2024

Functions in patchwork (0.0.1.9000)

plot_arithmetic

Plot arithmetic
wrap_plots

Wrap plots into a patchwork
wrap_ggplot_grob

Make a gtable created from a ggplot object patchwork compliant
cellGrob

Get a grob describing the content of an assemble_cell object
patchwork

patchwork: The Composer of ggplots
plot_annotation

Annotate the final patchwork
patchworkGrob

Convert a patchwork to a gtable
plot_layout

Define the grid to compose plots in
wrap_elements

Wrap arbitrary graphics in a patchwork-compliant patch
plot_spacer

Add a completely blank area
cell

Specify a plotting area in a layout
patchwork-package

patchwork: The Composer of Plots
guide_area

Add an area to hold collected guides
patchGrob

Get a grob describing the content of a patch object
area

Specify a plotting area in a layout
multipage_aling

Align plots across multiple pages
multipage_align

Align plots across multiple pages