IndrajeetPatil / ggstatsplot

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

modifying the secondary Y axes title #864

Closed tdlan80 closed 1 year ago

tdlan80 commented 1 year ago

Can you add a feature/arg to modify the secondary Y axes? The statistical test used for multiple pairwise comparisons are now displayed as a title of the secondary Y axis. can you provide an option to either remove this secondary axes title entirely from the plot? If I set results.subtitle = F, I will lose all test results, not just the pwc test type.

And, can the name of this pairwise comparison test be displayed as the where bf.message or the captionappears?

IndrajeetPatil commented 1 year ago

Can you add a feature/arg to modify the secondary Y axes? The statistical test used for multiple pairwise comparisons are now displayed as a title of the secondary Y axis. can you provide an option to either remove this secondary axes title entirely from the plot? If I set results.subtitle = F, I will lose all test results, not just the pwc test type.

You can pass additional arguments to {ggplot2} to customize the plot further to your liking:

library(ggstatsplot)

ggbetweenstats(
  mtcars, cyl, wt,
  ggplot.component = list(
    ggplot2::scale_y_continuous(sec.axis = ggplot2::dup_axis(name = "My custom test"))
  )
)
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.

Created on 2023-06-08 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.0 (2023-04-21) #> os macOS Ventura 13.4 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Europe/Berlin #> date 2023-06-08 #> pandoc 3.1.3 @ /usr/local/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> BayesFactor 0.9.12-4.4 2022-07-05 [1] CRAN (R 4.3.0) #> bayestestR 0.13.1 2023-04-07 [1] CRAN (R 4.3.0) #> BWStest 0.2.2 2018-10-18 [1] CRAN (R 4.3.0) #> cachem 1.0.8 2023-05-01 [1] CRAN (R 4.3.0) #> cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0) #> coda 0.19-4 2020-09-30 [1] CRAN (R 4.3.0) #> codetools 0.2-19 2023-02-01 [1] CRAN (R 4.3.0) #> colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.0) #> correlation 0.8.4 2023-04-06 [1] CRAN (R 4.3.0) #> curl 5.0.0 2023-01-12 [1] CRAN (R 4.3.0) #> datawizard 0.7.1.9 2023-05-30 [1] https://easystats.r-universe.dev (R 4.3.0) #> digest 0.6.31 2022-12-11 [1] CRAN (R 4.3.0) #> dplyr 1.1.2 2023-04-20 [1] CRAN (R 4.3.0) #> effectsize 0.8.3.11 2023-04-24 [1] https://easystats.r-universe.dev (R 4.3.0) #> emmeans 1.8.6 2023-05-11 [1] CRAN (R 4.3.0) #> estimability 1.4.1 2022-08-05 [1] CRAN (R 4.3.0) #> evaluate 0.21 2023-05-05 [1] CRAN (R 4.3.0) #> fansi 1.0.4 2023-01-22 [1] CRAN (R 4.3.0) #> farver 2.1.1 2022-07-06 [1] CRAN (R 4.3.0) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) #> fs 1.6.2 2023-04-25 [1] CRAN (R 4.3.0) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0) #> ggplot2 3.4.2 2023-04-03 [1] CRAN (R 4.3.0) #> ggrepel 0.9.3 2023-02-03 [1] CRAN (R 4.3.0) #> ggsignif 0.6.4 2022-10-13 [1] CRAN (R 4.3.0) #> ggstatsplot * 0.12.0 2023-06-02 [1] local #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0) #> gmp 0.7-1 2023-02-07 [1] CRAN (R 4.3.0) #> gtable 0.3.3 2023-03-21 [1] CRAN (R 4.3.0) #> highr 0.10 2022-12-22 [1] CRAN (R 4.3.0) #> htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.3.0) #> insight 0.19.2 2023-05-23 [1] CRAN (R 4.3.0) #> knitr 1.43 2023-05-25 [1] CRAN (R 4.3.0) #> kSamples 1.2-9 2019-05-20 [1] CRAN (R 4.3.0) #> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.3.0) #> lattice 0.21-8 2023-04-05 [1] CRAN (R 4.3.0) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.3.0) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) #> MASS 7.3-60 2023-05-04 [1] CRAN (R 4.3.0) #> Matrix 1.5-4.1 2023-05-18 [1] CRAN (R 4.3.0) #> MatrixModels 0.5-1 2022-09-11 [1] CRAN (R 4.3.0) #> memoise 2.0.1 2021-11-26 [1] CRAN (R 4.3.0) #> multcomp 1.4-23 2023-03-09 [1] CRAN (R 4.3.0) #> multcompView 0.1-9 2023-04-09 [1] CRAN (R 4.3.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.3.0) #> mvtnorm 1.2-1 2023-06-04 [1] CRAN (R 4.3.0) #> paletteer 1.5.0 2022-10-19 [1] CRAN (R 4.3.0) #> parameters 0.21.1 2023-05-26 [1] CRAN (R 4.3.0) #> patchwork 1.1.2 2022-08-19 [1] CRAN (R 4.3.0) #> pbapply 1.7-0 2023-01-13 [1] CRAN (R 4.3.0) #> performance 0.10.4 2023-06-02 [1] CRAN (R 4.3.0) #> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) #> PMCMRplus 1.9.6 2022-08-17 [1] CRAN (R 4.3.0) #> prismatic 1.1.1 2022-08-15 [1] CRAN (R 4.3.0) #> purrr 1.0.1 2023-01-10 [1] CRAN (R 4.3.0) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.3.0) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.3.0) #> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.3.0) #> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.3.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) #> Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.3.0) #> RcppParallel 5.1.7 2023-02-27 [1] CRAN (R 4.3.0) #> rematch2 2.1.2 2020-05-01 [1] CRAN (R 4.3.0) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.3.0) #> rlang 1.1.1 2023-04-28 [1] CRAN (R 4.3.0) #> rmarkdown 2.22 2023-06-01 [1] CRAN (R 4.3.0) #> Rmpfr 0.9-2 2023-04-22 [1] CRAN (R 4.3.0) #> rstantools 2.3.1 2023-03-30 [1] CRAN (R 4.3.0) #> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.3.0) #> sandwich 3.0-2 2022-06-15 [1] CRAN (R 4.3.0) #> scales 1.2.1 2022-08-20 [1] CRAN (R 4.3.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) #> statsExpressions 1.5.1 2023-05-23 [1] local #> stringi 1.7.12 2023-01-11 [1] CRAN (R 4.3.0) #> stringr 1.5.0 2022-12-02 [1] CRAN (R 4.3.0) #> styler 1.10.1 2023-06-05 [1] CRAN (R 4.3.0) #> SuppDists 1.1-9.7 2022-01-03 [1] CRAN (R 4.3.0) #> survival 3.5-5 2023-03-12 [1] CRAN (R 4.3.0) #> TH.data 1.1-2 2023-04-17 [1] CRAN (R 4.3.0) #> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.0) #> tidyr 1.3.0 2023-01-24 [1] CRAN (R 4.3.0) #> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.3.0) #> utf8 1.2.3 2023-01-31 [1] CRAN (R 4.3.0) #> vctrs 0.6.2 2023-04-19 [1] CRAN (R 4.3.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.3.0) #> xfun 0.39 2023-04-20 [1] CRAN (R 4.3.0) #> xml2 1.3.4 2023-04-27 [1] CRAN (R 4.3.0) #> xtable 1.8-4 2019-04-21 [1] CRAN (R 4.3.0) #> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.3.0) #> zeallot 0.1.0 2018-01-28 [1] CRAN (R 4.3.0) #> zoo 1.8-12 2023-04-13 [1] CRAN (R 4.3.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library #> #> ────────────────────────────────────────────────────────────────────────────── ```

Of course, you can also use the same approach to remove that label completely by setting name = "".

And, can the name of this pairwise comparison test be displayed as the where bf.message or the captionappears?

No, because this space is already quite congested with the existing details, and adding more information here would just make it even more difficult to decode. The behaviour you are describing used to be the default behaviour but I changed to the current one precisely for the reason I mentioned.

tdlan80 commented 1 year ago

Thanks, I should have looked into ggplot.component before. I understand that bf.message already fill-up the caption space.

And, yes, ggplot2::scale_y_continuous(sec.axis = ggplot2::dup_axis(name = " ", labels = NULL, breaks = NULL)) does work to remove the title of the duplicated axis. But, this might give off annoying warnings.

instead, this might be a better option: ggplot.component = list( theme(axis.title.y.right = element_blank(), axis.text.y.right = element_blank(), axis.ticks.y.right = element_blank())