patchwork is an R package by Thomas Lin Pedersen providing a simple API for composing multiple plots from the ggplot2 package system.
Questions tagged [patchwork]
174 questions
15
votes
2 answers
Combine and merge legends in ggplot2 with patchwork
I would like to combine two or more plots merging their legends.
For example, I can create some data and two scenarios as follows.
# packages
library(ggplot2)
library(patchwork)
# first plot
set.seed(07042020)
x <- runif(50)
y <- runif(50)
data1…

agila
- 3,289
- 2
- 9
- 20
13
votes
3 answers
Merging two y-axes titles in patchwork
Any ideas as to how I can "merge" two identical y-axes titles into one, and then place this y-axis title in the middle between the plot? I have succeded in merging legends by using plot_layout(guides = "collect") but I cannot seem to find anything…

Tiptop
- 533
- 5
- 19
10
votes
2 answers
Combine ggplotly and ggplot with patchwork?
Is it possible to combine a ggplotly and a ggplot with patchwork?
Example
This displays the two plots side by side
library(ggplot2)
library(plotly)
library(patchwork)
a <- ggplot(data.frame(1), aes(X1)) + geom_bar()
b <- ggplot(data.frame(1),…

dss
- 395
- 3
- 11
10
votes
1 answer
R package patchwork : titles for rows/columns
Is there a way to add titles by row or column using the patchwork package for combining plots?
Ex. with the arrangement : patchwork<- (p| p2 | p3)/ (p4| p5| p6), I would like one title for plots 1-3 and another for 4-6.

ZR8
- 131
- 1
- 9
10
votes
2 answers
set axes limits in patchwork when combining ggplot2 objects
When combining ggplot2 objects using patchwork I would like to be able to have an option that I could easily set an option for all the plots to have the same x-axis and/or y-axis range.
reprex:
library(patchwork)
library(ggplot2)
library(dplyr)
#>…

FMM
- 1,857
- 1
- 15
- 38
9
votes
1 answer
Manually position legend in Patchwork
I want to position a legend (common to all plots) in a blank space in a patchwork layout. From what I can find online I cannot manually position a legend using legend.position if I also use guides="collect" (but can use left, right etc.).
I have…

Esme_
- 1,360
- 3
- 18
- 30
9
votes
1 answer
How to minimize the white space created by the guide_area() function of the patchwork package in plots made with ggplot2?
I made 3 plots with the ggplot2 package. To arrange the plots in a single figure I used the patchwork package. In the arrangement, I put 2 plots at the top, the common legend below these plots and below the common legend the third plot. I created…

Daniel Valencia C.
- 2,159
- 2
- 19
- 38
9
votes
1 answer
Align multiple legends with patchwork
In this vignette of patchwork is explained how to combine multiple ggplots. One difficulty I encountered is to collect the legends and align/justify them properly when their titles are very different in number of characters.
Below is an example - I…

Valentin_Ștefan
- 6,130
- 2
- 45
- 68
8
votes
1 answer
Best way to add a text-only section in a {patchwork} of multiple ggplots?
When using {patchwork} to combine separate ggplots into the same graphic, I sometimes want to add one or more sections that are no plots at all, but basically a textbox.
As far as I can tell, the only time this is adressed in the patchwork…

Paul Schmidt
- 1,072
- 10
- 23
8
votes
1 answer
How to reduce the space between to plots when using patchwork
Hi all I am working with a little dataframe to build some plots in ggplot2. My dataframe is df and I include it as dput() at the end. I have the plots and the problem rises when I use patchwork. I want the final plot without spaces so that the line…

Duck
- 39,058
- 13
- 42
- 84
7
votes
1 answer
Colour in title of patchwork of ggplots using ggtext?
How can a patchwork of ggplots be given a colourful title using ggtext?
Example
Suppose we have four plots
library(ggplot2)
library(patchwork)
library(ggtext)
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp)) +
ggtitle('Plot 1')
p2 <-…

stevec
- 41,291
- 27
- 223
- 311
6
votes
1 answer
Combining plots with patchwork when plot aspect ratio is 1
I have ran into an issue with combining plots using patchwork when theme(aspect.ratio = 1).
Provided are a a few examples:
library(tidyverse)
library(patchwork)
# Create the base plots
plotlist = list(
fig1 = iris %>%
filter(Species ==…

mhovd
- 3,724
- 2
- 21
- 47
6
votes
2 answers
Add legend between patchwork main title and plot titles
Is it possible to have legend below 'main' title' and above plot titles using patchwork?
library(ggplot2)
library(patchwork)
p1 <- ggplot(mtcars, aes(disp, wt, color = factor(gear))) +
geom_point() +
labs(title = "first plot title")
p2 <-…

det
- 5,013
- 1
- 8
- 16
6
votes
1 answer
How to adjust the font style of tags with plot_annotation in figures assembled with patchwork?
I have a figure assembled with patchwork as follows:
library(ggplot2)
library(patchwork)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p1 + p2 + plot_annotation(tag_levels =…

mt1022
- 16,834
- 5
- 48
- 71
6
votes
3 answers
How to add a table to a ggplot?
I am trying to combine (in a single chart) a regular ggplot chart with a table obtained with flextable.
Consider the following example:
library(tidyverse)
library(patchwork)
mydf <- tibble(a = c(1,2,3,4,5,4),
b = c(4,4,4,3,3,3))
p1…

ℕʘʘḆḽḘ
- 18,566
- 34
- 128
- 235