243 questions
1
vote
2
answers
141
views
ggplot2 + patchwork: making a plot background transparent when overlapping another panel
I am trying to compose a figure with multiple panels. I have a lot of empty space and I am trying to overlap some of the rectangular panels, so I can make some of them larger. However, setting in ...
0
votes
1
answer
89
views
Combine linetype legend but keep separate color legends and arrange separately ggplot2
I'm trying to graph coefficients (points) and standard errors (error bars) for different metrics and different double machine learning algorithms, across 3 different examples (3 different plots). I've ...
0
votes
2
answers
74
views
Using patchwork with geofacet, geom_rect's showing up in unused facets
I'm trying to recreate a stunning and often shared graphic "Where are Americans Born." It involves using facet_geo to display the percent of out-of-state and foreign born residents for each ...
1
vote
1
answer
90
views
Collecting axes with patchwork::plot_layout for a 2x2 plot
I have a simple plot and I want to collect the x and y axes together:
library(ggplot2)
library(patchwork)
p1 <- ggplot(mtcars, aes(mpg, disp)) +
geom_point() +
labs(x = "mpg", y = &...
0
votes
2
answers
102
views
Place the shared legend inside the plot grid as opposed to besides it [duplicate]
I have 3 plots that I want to arrange in a 2x2 format. They all share the same legend, and I want to place the legend in the bottom right space, where a fourth figure would fit. So far, I have tried ...
1
vote
2
answers
81
views
Increase item spacing in collected legend
patchwork provides an option to use only one legend in case the legend is identical across different sub-panels.
Changing the vertical spacing between legend items does not work as I would expect for ...
-4
votes
1
answer
152
views
Align two separate ggplots at their x axis but keep their y axis independent
I would like to generate a few different plots in ggplot2 and assemble them in an image tool like MS publisher or Inkscape to get a single publication-ready figure.
Ideally, I would like to produce ...
1
vote
1
answer
235
views
How to handle legend properly with patchwork
It seems to me that this was working before.
I am using patchwork 1.3.0 , with ggplot2 3.5.2.
Here is my problem:
p1 <- ggplot(iris,aes(Sepal.Length,Sepal.Width,color = Species))+
geom_point()
...
0
votes
2
answers
114
views
How to combine ggplot2 and density plots using patchwork with aligned axes and proportional sizing?
I'm visualizing ecological niche shifts by combining a scatter plot (scaled environmental values) with marginal density plots of the respective variables — similar to a marginal histogram layout. I am ...
2
votes
3
answers
117
views
How to properly combine two ggplots and properly align axis and strips/titles?
I need to combine two ggplots. They should have labels (A, B, and C) as for being used in a publication. The first plot is a facet_wrap(). This is my code:
library(ggplot2)
library(dplyr)
library(...
1
vote
2
answers
111
views
Create plot with variable height in facet_wrap
I want to reproduce this graph:
From the following paper: https://www.journals.uchicago.edu/doi/10.1086/730711
I have used facet wrap, but it does not have variable heights. Facet grid would not work ...
0
votes
1
answer
80
views
Legend not aligning under the graph using ggplot2
This is a follow up to my earlier question, elegantly answered by the community.
I am using the same dataset as in the earlier question, given below:
topclones<- structure(list(CTaa_beta = c("...
1
vote
1
answer
73
views
Center patchwork graphs in the second row [duplicate]
I am trying to place the 5 graphs in a way that Three graphs comes on top row and 2 graphs in bottom row but the problem is the graphs at bottoms appear either on right or left side. I want to place ...
1
vote
1
answer
117
views
Why does wrap_plots() fail when combining sub-layouts with unit() widths and heights in patchwork?
I'm using the patchwork package in R to arrange 6 plots into a 3-row by 2-column layout, where each column has plots stacked vertically.
Each vertical column works when created independently, with ...
6
votes
2
answers
299
views
Fixed aspect ratio prevents patchwork to collect axis titles
When merging axis labels with the patchwork package, problems occurred (see this question). From the answer of the question, I applied the idea of the example code to my concrete example, in which I ...
1
vote
2
answers
145
views
How to ensure a shared x- and y-axis across multiple ggplot2 plots in patchwork
I am creating a 2x2 matrix of raster plots using ggplot2 and patchwork, where each plot is generated from a different dataset. I want to ensure that the x- and y-axis of these plots, which are equal, ...
1
vote
1
answer
160
views
Combine three plots keeping same width with patchwork
I am trying to combine three plots, and I would like to have one plot on top and two in a second row one next to the other. All plots should have same height and width. I am using patchwork package. ...
0
votes
0
answers
100
views
How to create a shared legend between plots that don't share all categories [duplicate]
I am trying to create a panel of scatterplots displaying different subsections of the same dataset. I want to combine all of their legends, but because of the subsetting, no individual plot contains ...
1
vote
1
answer
92
views
patchwork's operations on the legend position of a subgraph during merging
In the most straightforward case, the patchwork does a good job of pairing its two panels, but it also seems to ignore the subdiagram's specification of the location of the legend legend.box.spacing:
...
2
votes
1
answer
122
views
Collecting common legends while keeping a specific legend beside each plot in patchwork
I am making a multi-panel figure in R using wrap_plots from the patchwork package, and I'd like to have the final plot show a common legend for point shape and color, but have each plot keep its own ...
1
vote
1
answer
57
views
Fine control over positioning of the Legend in a combined graph using ggplot
I'm pretty new to R and so far have successfully managed to solve all issues I encountered using a combination of stackoverflow, manuals, Google and ChatGPT. So before I start I have to say a big ...
3
votes
0
answers
125
views
Conflict between multiple uses of inset_element and function plot_annotation
A situation was encountered when merging subgraphs in using patchwork. It is necessary to use inset_element to merge multiple times and then label at the end. But in the case of labeling the following ...
1
vote
1
answer
43
views
grid.arrange's relative height argument didn't works well in RMarkdown
Preamble
I have 2 plots in ggplot2 and want to put them in RMarkdown document. I'm mainly using grid.arrange to do that. But since those plots have completely different heights, I need to adjust using ...
3
votes
2
answers
63
views
Adding and aligning plot to spare facet at end of facet_wrap()
This is similar to the question here, but I am interested in how to add and align a separate plot to a spare panel that may exists at the end of a facet_wrap() call.
Currently I am thinking it might ...
2
votes
1
answer
156
views
Issue combining plots with patchwork in R: Inconsistent spacing between panels in two-level patched plots
I'm trying to combine several plots using patchwork in R, but I'm encountering an issue with misalignment and inconsistent spacing between the panels. The first set of plots is drawn with double ...
0
votes
1
answer
100
views
merging legends with ggplot and patchwork
With the code
library(ggplot2)
library(patchwork)
dat.a <- data.frame(year=rep(2021:2024,times=2),group=rep(c("A","B"),each=4),val=runif(8,1,10))
dat.b <- data.frame(year=...
1
vote
1
answer
151
views
How to delete legend from inset but keep legend in the main plot in a patchwork layout in R?
I need to create a plot layout with two main plots having an inset each. I'd like to keep the legend in the main plots (positioned inside the plot), but I need to show the insets without any legend. I ...
2
votes
1
answer
62
views
Why legend is not showing up in plot layout using patchwork in R?
Based on what I read in this answer , what I am trying to do should work. However, the legend is missing. I want to add a legend in the center of a guide space of two plot spaces.
library(ggplot2)
...
1
vote
1
answer
64
views
How can I merge the identical legends that have different size scales on a plot_layout (patchwork)? [duplicate]
I am attempting to place multiple graphs into one page using patchwork. I have the separate graphs as Group 1 and Group 2 with their 2 legends in each case.
However, when I use patchwork to put them ...
1
vote
2
answers
530
views
Can you center a plot using R patchwork [duplicate]
This is about organizing plots in R markdown document. Say we create three plots:
library(patchwork)
library(tidyverse)
a <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + ggtitle("Plot A"...
0
votes
0
answers
131
views
Including 'guides = collect' causes patchwork to return error message 'Error in as.unit(value) : object is not coercible to a unit'
A new error message popped up with patchwork today in code that used to work.
Here's a reproducible example:
library(tidyverse)
library(magrittr)
library(patchwork)
d1 <- tibble(
x = rep(1, 5),
...
1
vote
1
answer
110
views
ggplot arrange multiple scales/legends in grid layout
How do you work around space issues when the scales/legends do not fit vertically beside a plot? I would like to arrange them in a grid with n-rows and m-cols (similar to this question) and align each ...
1
vote
1
answer
470
views
Get a shared axis title for a combined plot using patchwork [closed]
I tried to create a plot with shared axis-labels. The problem was, that I wanted my legend under my plots, because my plots otherwise would be too compressed. I didn't managed to creade a good plot ...
1
vote
1
answer
223
views
How to make combined legend for ggplots using either patchwork() or ggarrange() etc
I am struggling to make a legend that I want for my graph. Here is what the graph currently looks like (it's not a final version, I know it's not super pretty)
I am frustrated by the fact that I can'...
0
votes
1
answer
82
views
In patchwork of multiple ggplots, can't set legend position [duplicate]
A simple patchwork of ggplot has left me uncertain how to locate the legend in the overall figure.
Here's the data and the two plots
library(tidyverse)
library(patchwork)
library(magrittr)
set.seed(...
0
votes
1
answer
466
views
Collecting Axes using plot_layout() in Patchwork: Aligning and Plotting Sediment Core Images and Downhole Logs
Using a combination of ggplot2, magick, and patchwork, I've gotten pretty close to getting a programmatic sediment core downhole log plot with a scaled photograph aligned along the left y-axis. See ...
2
votes
1
answer
279
views
patchwork - inset_element(): size and position
I have two plots.
The first one (big) is the one which should function as the "background plot".
The second (small) should be the inset.
How can i adjust the size of the inset?
How to ...
1
vote
3
answers
385
views
How to align inset map (with coord_sf) in patchwork?
I'd like to plot an inset map in the top left corner of another map using package patchwork. Yet, when using coord_sf(), the alignment does not work anymore. How to solve this to ensure the inset map ...
3
votes
1
answer
534
views
Draw lines connecting individual data points in grouped bar plot - ggplot
I have a grouped bar plot (two conditions with two groups in each). I am not having trouble creating the group bar plots, but I am interested in putting individual data points on the plot and ...
1
vote
1
answer
150
views
Plot too Wide in Patchwork (R)
I've been struggling to understand the patchwork package in R. The barchart on the right of the plot should be much thinner, like the one on top of the scatter plot. Below is my code. Any suggestions?
...
2
votes
1
answer
233
views
Only collect partial of legends with patchwork
I am trying to only "collect" partial of legends with patchwork, below is a minimal example.
library(patchwork)
library(ggplot2)
p1 <- ggplot(mtcars, aes(mpg, disp, color = factor(vs))) +...
2
votes
2
answers
934
views
Specify which legend to keep in wrap_plots
I'm looking to combine multiple graphs generated from different functions into a single display. Specifically, I want to only keep the legend of the first graph in the wrap.
Here is a minimal version ...
2
votes
2
answers
105
views
Add annotation or title outsides border
In this example, I added a border to the three plots:
library(ggplot2)
library(patchwork)
theme_border <- theme_gray() +
theme(plot.background = element_rect(fill = NA, colour = 'black',
...
0
votes
1
answer
73
views
Align y axis labels
I am creating three seperate plots which I then combine using patchwork. The third plot that I make uses facet_grid in order to add a secondary x axis with the years showing. But I think this somehow ...
1
vote
1
answer
375
views
Combining Plotly and ggplot2 charts with Patchwork in one Facet
I want to combine two charts prepared with Plotly and ggplot2 into one PDF. Below, you can see the code for the preparation of the charts:
library(ggplot2)
library(plotly)
library(dplyr)
library(...
1
vote
1
answer
81
views
Misaligned patchwork of facets when using free scaling and mixed-format labels
library(tidyverse)
library(scales)
library(patchwork)
df <- tibble(
date = rep(seq(ymd("2024-01-01"), ymd("2024-12-01"), by = "month"), 2),
var1 = c(seq(1e6, 2....
0
votes
1
answer
318
views
How to align plots with facet_wrap2 and patchwork?
I am having difficulty aligning my grid figure correctly when I have removed the repeating tick labels on the y-axis while combining other facet wraps with different length tick labels in patchwork. I ...
2
votes
1
answer
138
views
How to import operators from the patchwork package into my own package in R?
Similar questions have been asked here, here, and here. However, they don't exactly solve the issue Im having.
Essentially, I am creating a package that has a function that creates a bar plot and then ...
0
votes
1
answer
192
views
How do I combine several ggplot2 plots using patchwork?
When trying to add two ggplot objects (plots) using + from patchwork, I get the error as shown below. What could be the issue?
require(patchwork)
ex.df <- data.table(
x1 = rnorm(1000, 20, 50),
...
0
votes
0
answers
542
views
Patchwork doesn't render in Quarto
I would like to use patchwork to plot two graphs side by side. Unfortunately, it returns an error and I don't know why. Here is some reproducible code:
---
title: "Test"
format: html
---
```...