patchwork icon indicating copy to clipboard operation
patchwork copied to clipboard

[Feature request] Method to collect other captions, axis labels, (titles, subtitles, ...?)...

Open aghaynes opened this issue 2 years ago • 0 comments

It would be great to have a method to collect other information besides the guides. Captions, x and y labels... and these things might be collected.

I have a case for example where I use a function to construct a pair of ggplots and then use patchwork to put them beside each other in some cases. The guides are collected, which is ideal, but the captions are duplicated.

Obviously it would be possible to do the caption through patchwork instead of in the function.

Oddly, while doing a reprex, I notice that the guide collection doesnt always seem to work for sizes:

library(ggplot2)
library(patchwork)
library(magrittr)

fn <- function(dat){
  ggplot(dat, 
         aes(x = x, y = y, size = size)) + 
    geom_point() +
    labs(caption = "something")
}

p1 <- data.frame(x = rnorm(10), y = 1, size = rnorm(10)) %>% 
  fn()

p2 <- data.frame(x = rnorm(10), y = 1, size = rnorm(10)) %>% 
  fn()

p1 + p2 + plot_layout(guides = "collect")

Created on 2021-10-28 by the reprex package (v2.0.0)

aghaynes avatar Oct 28 '21 13:10 aghaynes