thomasp85 / patchwork

The Composer of ggplots
https://patchwork.data-imaginist.com
Other
2.47k stars 163 forks source link

error when composing aligned plots #254

Closed nitrato closed 2 months ago

nitrato commented 3 years ago

Hi, I have a question regarding the very handy patchwork extension to ggplot2. In the following chunk, I wonder why lines that I tagged with ### give me this error: Error in grid.Call.graphics(C_setviewport, vp, TRUE) : 'layout.pos.row' incorrect

Any help would be highly appreciated Best, David

`p1 <- ggplot(msleep) + 
geom_boxplot(aes(x = sleep_total, y = vore, fill = vore)) +
p3 <- ggplot(msleep) + 
geom_point(aes(x = bodywt, y = sleep_total, colour = vore), size = 3, alpha = 0.7)

p1_bis <- p1 + theme(legend.position = "none")
p3_dims <- get_dim(p3)
p1_aligned <- set_dim(p1_bis, p3_dims)
p1_aligned
p1 + p1_aligned ###

plots_aligned <- align_patches(p1, p2, p3, p4)
for (p in plots_aligned)
  plot(p)

plots_aligned[[1]] + plots_aligned[[2]] ### `
thomasp85 commented 1 year ago

The set_dim() and get_dim() functions are not meant to be used together with further composition but rather to align plots across multiple pages.

Can you describe what you are trying to achieve with your code and I can help you with the right way