INTRODUCTION
**Please note** This tutorial is largely taken from the relevant package github page **Please note**
The package patchwork is beeing used to as a connector between different ggplots. More specifically it display them in one picture.
Installation
You can install patchwork from github with:
# install.packages("devtools")
devtools::install_github("thomasp85/patchwork")
Its usage is quite straighforward if you already know the how to use ggplot2.
library(ggplot2)
library(patchwork)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p1 + p2

Of course it is not necessary to create 2 separate objects in order to use patchwork.
ggplot(mtcars) +
geom_point(aes(mpg, disp)) +
ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear))

In order to adjust the settings of your layout you just need to use plot_layout().
p1 + p2 + plot_layout(ncol = 1, heights = c(3, 1))

The plot_spacer() is used if you want to add or remove space between your plots.
p1 + plot_spacer() + p2

A really useful feature that patchwork provides is that it enables the user to create “subplots”.
p3 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec))
p4 <- ggplot(mtcars) + geom_bar(aes(carb))
p4 + {
p1 + {
p2 +
p3 +
plot_layout(ncol = 1)
}
} +
plot_layout(ncol = 1)

Advanced Features
What is interesting about patchwork is that you can use “+”, “-” operators in order to define the nesting level:
p1 + p2 + p3 + plot_layout(ncol = 1)

Look at the code below and notice that now pi and p2 are “nested-like”:
p1 + p2 - p3 + plot_layout(ncol = 1)

The next two operators that enable plot placing are | and / for horizontal and vertical layouts, respectively. You can use them in the same operation.
(p1 | p2 | p3) /
p4

Last but not least you can use & or * instead of having to set the layout settings for each separate plot. This is very useful feature especially if you need to combine many plots together. * alterate plots on the current nesting level:
(p1 + (p2 + p3) + p4 + plot_layout(ncol = 1)) * theme_bw()

while & :
p1 + (p2 + p3) + p4 + plot_layout(ncol = 1) & theme_bw()

Now, let’s move on to the first set of real exercises on the patchwork package!



This would have been so much better with images
I agree. This is a blog about plotting and we can’t see any of the plots.
Added. Tnx for feedback
Added. Tnx for feedback :)
This seems to be just copied from the github readme for the patchwork package page, but without the images that make it useful.
Images were added. The interesting part although is the exercises that follow. Tnx for feedback
Is there anyway the example could explain what each stand for? For example gear, disp. Are these default?