patchwork icon indicating copy to clipboard operation
patchwork copied to clipboard

Complex plot_layout resulting in plots of different widths although having the same area

Open jospueyo opened this issue 3 years ago • 0 comments

I'm assembling eleven plots with patchwork. But, weirdly, the top right plot is narrower than the others despite having the same area defined in plot_layout(). Here is a reprex:

create_plot <- function(x=NA){
  tibble(name = sample(letters[1:5], 50, replace=T),
               value = sample(letters[6:10], 50, replace=T)
               ) %>% 
  count(name, value) %>% 
  ggplot(aes(x=name, y=n, fill=value))+
  geom_col(show.legend = F)
}

areas <- c(  #top left bottom right
  area(1,1,1,4),    
  area(1,5,1,8),
  area(1,9,1,12),
  area(2,2,2,5),
  area(2,8,2,11),
  area(3,2,3,5),
  area(3,8,3,11),
  area(4,2,4,5),
  area(4,8,4,11),
  area(5,2,5,5),
  area(5,8,5,11)
)

plot(areas)

map(1:11, create_plot) %>% 
wrap_plots()+guide_area()+
  plot_layout(design = areas)

Here is the result:

image

All plots have the same width, except the top right one, which is narrower. I also tried using the grid string with the same result:

areas <- "
  AAAABBBBCCCC
  #DDDD##EEEE#
  #FFFF##GGGG#
  #HHHH##IIII#
  #JJJJ##KKKK#
"

I had first opened a question in stackoverflow.

jospueyo avatar Jun 13 '22 05:06 jospueyo