Carmen Sandoval
Carmen Sandoval

Reputation: 2356

patchwork::plot_layout: one single plot on top row, then variable number of plots in subsequent rows, but keep same width for all plots

I've made a series of plots that I want to print on the same page.

The main plot, dotplot_summary, is a summary of the plots in dotplots_indiv <- list(p1, p2, p3).

I'd like the first plot to be the same size as the plots on the second row, but I can't figure out how.

My reprex is here: https://pastebin.com/wjhmSFiB

p_indiv <- wrap_plots(dotplots_indiv) 
patchwork <- (dotplot/p_indiv) + plot_layout(nrow = 2, widths = c(1, 3)

I was thinking of adding plot spacers, but the number of plots that can fit in the lower row is variable.

Thanks.

enter image description here

Upvotes: 2

Views: 1476

Answers (1)

Duck
Duck

Reputation: 39605

I was not able to reproduce the issue with the data you shared as it is giving errors but I sketched an example. You can use the layout option in wrap_plots() defining a matrix style like this (I have used iris data):

library(patchwork)
library(ggplot2)
#Plot 1
G1 <- ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+
  geom_point()
#Plot 2
G2 <- ggplot(iris,aes(y=Sepal.Length,x=Sepal.Width))+
  geom_point()
G3 <- ggplot(iris,aes(y=Petal.Width,x=Sepal.Width))+
  geom_point()
G4 <- ggplot(iris,aes(y=Petal.Length,x=Petal.Width))+
  geom_point()
#Wrap
#Layout
layout <- '
#A#
BCD
'
#Plot
wrap_plots(A = G1, B = G1,C=G2,D=G3, design = layout)

Output:

enter image description here

All plots will keep same dimension, rather than this:

enter image description here

Which follows a code structure similar to the one you shared.

Upvotes: 1

Related Questions