Skip to content

Arrangement of plots with absolute dimensions using theme(panel.widths, panel.heights) in ggplot2 v4.0.0 #452

@jbengler

Description

@jbengler

Since ggplot2 4.0.0 it is possible to generate plots with absolute dimensions using theme(panel.widths, panel.heights)

When feeding those plots into patchwork, one runs into some unexpected results. Here are some examples:

library(ggplot2)
library(patchwork)

p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) + 
  theme(panel.widths = unit(30, "mm"), panel.heights = unit(30, "mm"))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) + 
  theme(panel.widths = unit(30, "mm"), panel.heights = unit(30, "mm"))
p3 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) + 
  facet_wrap(vars(gear)) +
  theme(panel.widths = unit(30, "mm"), panel.heights = unit(30, "mm"))

p1 + p2 # looks good
p1 / p2 # looks good
p1 | p2 # looks good
(p1 | p2) / (p2 + p1) # vertical spacing dynamic instead of fixed
(p1 | p2) / p1 # bottom plot looses its absolute width

p1 + p3 # unexpected
p1 / p3 # looks good
p1 | p3 # unexpected
(p1 | p3) / (p3 + p1) # unexpected
(p1 | p3) / p1 # unexpected

Sorry for bringing up this potentially unpleasant topic 🫣

Best wishes
Broder

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions