patchwork
patchwork copied to clipboard
Issue with combining plots when aspect ratio is 1
As asked on Stack Overflow, I have encountered an issue with combinig plots using patchwork when the aspect ratio is 1 for all plots.
library(patchwork)
# Create the base plots
plotlist = list(
fig1 = iris %>%
filter(Species == "setosa") %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point(),
fig2 = iris %>%
filter(Species == "versicolor") %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point(),
fig3 = iris %>%
filter(Species == "virginica") %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point()
)
Here the patchwork combines the plots nicely
plotlist$fig1 / (plotlist$fig2 + plotlist$fig3)
However, when changing the aspect ratio, something happens:
plotlist = lapply(plotlist, function(x) {
x + theme(aspect.ratio = 1)
})
Notice the large gap between plots. Instead, I would like the plots in the second row to be almost directly under the first row.
plotlist$fig1 / (plotlist$fig2 + plotlist$fig3)
Any recommended solutions?
I have written a solution for you on stack overflow that seems to produce your desired result. But in the process of writing the solution, I did uncover another bug which I have opened in #274. Cheers.