IndrajeetPatil / ggstatsplot

Enhancing {ggplot2} plots with statistical analysis 📊📣
https://indrajeetpatil.github.io/ggstatsplot/
GNU General Public License v3.0
2k stars 185 forks source link

Update with change from cowplot::plot_grid to patchwork breaks the grouped_ functions #540

Closed tinalasisi closed 3 years ago

tinalasisi commented 3 years ago

I just updated a R and Rstudio so I had to reinstall a lot of libraries and when I reinstalled ggstatsplot, I found that I had some issues with previously functioning plots.

Long story short, after fishing around, I found out that certain arguments I was passing that worked before the update don't anymore because they exist only in cowplot::plot_grid but not in patchwork.

For example, if I run:

plt_anc_pheno<- ggstatsplot::grouped_ggscatterstats(
  data = df_pheno_gwas_pc_long %>% 
    filter(!grepl("resid", phenotype)),
  x = AFR,
  y = value,
  grouping.var = phenotype,
  bf.message = FALSE,
  marginal = FALSE,
  plotgrid.args = list(ncol = 3, labels = "auto"),
  ggstatsplot.layer = FALSE,
  ggplot.component = list(theme(text = element_text(size = 8)))
)

I get this error:

Error: Only know how to add ggplots and/or grobs

But if I change the plotgrid.args to a syntax that's compatible with the patchwork update:

plt_anc_pheno<- ggstatsplot::grouped_ggscatterstats(
  data = df_pheno_gwas_pc_long %>% 
    filter(!grepl("resid", phenotype)),
  x = AFR,
  y = value,
  grouping.var = phenotype,
  bf.message = FALSE,
  marginal = FALSE,
  plotgrid.args = list(ncol = 3, tag_level = "keep"),
  annotation.args = list(tag_levels = "a"),
  ggstatsplot.layer = FALSE,
  ggplot.component = list(theme(text = element_text(size = 8)))
)

Basically replacing plotgrid.args = list(ncol = 3, labels = "auto") with plotgrid.args = list(ncol = 3, tag_level = "keep"), annotation.args = list(tag_levels = "a")

Then everything is just fine.

If there's any way to fix this bug by writing in something that automatically fixes old syntax, that would be really handy for people (i assume I might not be the only one who dealt with this bug).

Maybe throwing a more detailed error if someone adds the labels = input?

Hope this helps - happy plotting!

IndrajeetPatil commented 3 years ago

Sorry for the trouble. Unfortunately, this breakage is unavoidable, and something I did not think about when I wrote this NEWS item, so thanks for pointing it out to me! I will update the NEWS item to highlight this possibility.

Screenshot 2021-03-14 at 16 39 23

There only two ways to save this from failing:

  1. Adapt to the patchwork conventions
  2. Use something like https://cran.r-project.org/web/packages/groundhog/index.html this to ensure reproducibility.

I switched from cowplot to patchwork to reduce the clutter in API (read no. of arguments) and so I am hesitant to add more arguments (like labels) only to save past code from breaking. 😢