ggstatsplot icon indicating copy to clipboard operation
ggstatsplot copied to clipboard

Dropping unused factors result in unconsistent plots when grouping

Open emilopezcano opened this issue 2 years ago • 1 comments

https://github.com/IndrajeetPatil/ggstatsplot/blob/1fa219dd7440af5955ddc34aaf1911549422e10e/R/ggbarstats.R#L79

If you make the drop unused levels optional with an argument, more consistent plots can be obtained.

image

emilopezcano avatar Mar 27 '22 12:03 emilopezcano

Worked for me:

  • Comment this line:

https://github.com/IndrajeetPatil/ggstatsplot/blob/1fa219dd7440af5955ddc34aaf1911549422e10e/R/helpers_ggcatstats_graphics.R#L21

  • Add an drop.unused.levels argument to the function

  • Change this line and add another one:

https://github.com/IndrajeetPatil/ggstatsplot/blob/1fa219dd7440af5955ddc34aaf1911549422e10e/R/ggbarstats.R#L150

paletteer::scale_fill_paletteer_d(paste0(package, "::", palette), name = "",
                                  drop = drop.unused.levels) +
scale_x_discrete(drop=drop.unused.levels)

I am not sure how this affects to the computation of statistics or further side effects, so I am not submitting a pull request for the time.

image

emilopezcano avatar Mar 27 '22 16:03 emilopezcano