Can't figure out how to control ggplot layout using patchwork in this particular way

I've reviewed the patchwork documentation, but I'm still not sure of how to move my plot between positions, like so:

library(patchwork)
library(ggplot2)

p <- ggplot(mtcars, aes(x=mpg, y=cyl)) + geom_point()

p + p + p + p +
  plot_spacer() + p + p + p + plot_layout(nrow=2)

But instead I want :

Hi @cwright1,

You may want to play around with custom layouts using the design argument to plot_layout(). For example:

library(ggplot2)
library(patchwork)

p <- ggplot(mtcars, aes(x=mpg, y=cyl)) + geom_point()

p + p + p + p + p + p + p + 
  plot_layout(
    design = '
    #BCD
    ABCD
    AEFG
    #EFG
  '
  )

1 Like

Hi @mattwarkentin ,

Thanks for this! I've played around with my 'real' example for a long time, but maybe I'll just have to accept that the proportions can't remain unchanged and one of the plots is in the 'middle' ?

For example, in your solution here the bottom plots (E/F/G) and the in-between plot (A) are taller than the other plots. Is there really no way to keep them the same proportions ?

Thanks for teaching me about this!

Hi @cwright1,

I'm actually not really sure why the plots don't occupy the same amount of space. There must be some plot alignment stuff going on in the background that I don't quite understand.

If we are lucky, perhaps @thomasp85 can shed further insights into this issue. If not, you may consider filing an issue over at the {patchwork} GitHub for more help.

1 Like