243 questions
1
vote
2
answers
110
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
2
answers
73
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 ...
0
votes
2
answers
96
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 ...
-4
votes
1
answer
141
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 ...
0
votes
2
answers
104
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 ...
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 ...
1
vote
1
answer
67
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 ...
6
votes
2
answers
289
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
1
answer
141
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. ...
1
vote
1
answer
89
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:
...
1
vote
1
answer
51
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 ...
1
vote
1
answer
42
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 ...
2
votes
1
answer
142
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 ...
1
vote
1
answer
144
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 ...
1
vote
1
answer
61
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 ...
0
votes
0
answers
108
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
433
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 ...
0
votes
1
answer
79
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(...
2
votes
1
answer
273
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 ...
3
votes
1
answer
508
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 ...
2
votes
1
answer
215
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
99
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',
...
1
vote
1
answer
360
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(...
0
votes
1
answer
299
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 ...
0
votes
1
answer
174
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),
...