patchwork
patchwork copied to clipboard
Unexpected plot size with design formula
Hi folks,
Following code:
library(ggplot2)
library(patchwork)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p21 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p3 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec))
p31 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec))
p32 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec))
design <- "
ABD
ABD
ABE
ACE
ACF
ACF
"
p1 + p2 + p21 + p3 + p31 + p32 + plot_layout(design = design) + plot_annotation(tag_levels = "A")
produces figure in which plot E is bigger than plots D & F.
I would expect plots in 3rd column to be of the same size. Is there a way to achieve that using design formula?
Thank you in advance for help, Amel
You are running your head into something that trips a lot of people up but is integral to patchworks layout mechanism. Only the panel area is part of the sizing - any axes, titles, etc will stretch the area in between by a fixed amount. The way to ensure that the third column will have all plots at equal size is to nest it into its own sub-patchwork