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

Decimals won't work #926

Closed dax44 closed 6 months ago

dax44 commented 7 months ago

k parameter set in ggbetweenstats won't work.

ggbetweenstats(mtcars, am, wt, k = 3L)

gives

image

Can you help me with number of decimals in central tendency measures?

IndrajeetPatil commented 7 months ago

Sorry about that. This argument has now been renamed to digits. If you update to use latest CRAN ggstatsplot (0.12.3), using digits should work.

dax44 commented 7 months ago

Thanks. I'll check that after merging 0.12.3

IndrajeetPatil commented 7 months ago

0.12.3 is already on CRAN: https://cran.r-project.org/web/packages/ggstatsplot/index.html

dax44 commented 7 months ago

Indeed since 0.12.3 digits woks. Thanks

RainRam commented 6 months ago

Decimal issue version 0.12.3 ggbetweenstats( ... digits = "signif3" ... ) there is no "round (x, digits)" founction there, what can I do to remove so many unwanted zero? could you help me address this issue? thank you

IndrajeetPatil commented 6 months ago

Can you please provide a reproducible example?

RainRam commented 6 months ago

okay, ggs_exp.csv

Rcode: plt <- ggbetweenstats( data = ggs_exp,

caption = "",

p.adjust.method = "none",

type = "np",#non-para digits = "scientific1",#decimal package = "ggsci", palette = "default_jco", ggsignif.args = list(textsize = 6, tip_length = 0.01,family= "Arial"), centrality.label.args = list(size = 6, nudge_x = 0.4, segment.linetype = 4, min.segment.length = 0, y=100), x = x, y = y ) +

Add labels and title

labs( x = "Income quintiles", y = expression(paste("Overall income")) )+ theme_bw()+

Customizations

theme( legend.position = "",

This is the new default font in the plot

text = element_text(family = "Arial", size = 16, color = "black"),
plot.title = element_text(
  family = "Arial", #family = "Lobster Two"
  size = 20,
  face = "plain",
  color = "#2a475e"
),
# Statistical annotations below the main title
plot.subtitle = element_text(
  hjust = 0.2,
  family = "Arial", #family = "Roboto"
  size = 20, 
  face = "plain",
  color="#1b2838"
),
plot.title.position = "plot", 
axis.text = element_text(size = 20, color = "black"),
axis.title = element_text(size = 24),
axis.title.y.right = element_text(size = 24)

)+ theme( axis.ticks = element_blank(), axis.line = element_line(colour = "grey50"), panel.grid = element_line(color = "#b4aea9"), panel.grid.minor = element_blank(), panel.grid.major = element_blank() ) plt

RainRam commented 6 months ago

I saw a fuction requested by other person in another decimal-related issue report, when the p values within figure are less than 0.001, they can be presented as "< 0.001", if they > 0.001, showing the actual number, whether the following fuction can address the decimal issue

specify_decimal_p <- function(x, k = 3, p.value = FALSE) {

for example, if p.value is 0.002, it should be displayed as such if (k < 3 && isTRUE(p.value)) k <- 3

formatting the output properly output <- trimws(format(round(x = x, digits = k), nsmall = k), which = "both")

if it's a p-value, then format it properly if (isTRUE(p.value) && output < 0.001) output <- "< 0.001"

this will return a character return(output) }

IndrajeetPatil commented 6 months ago

I can't reproduce this behaviour.

Are you sure you have updated all the packages?

Also, are you sure you are not changing digits via options() somewhere (e.g. .Rprofile)?

Here is a minimal reproducible example using your data:

library(ggstatsplot)

ggs_exp <- readr::read_csv("/Users/indrajeetpatil/Downloads/ggs_exp.csv")

ggbetweenstats(
  x = x,
  y = y,
  data = ggs_exp,
  type = "np",
  digits = "scientific1"
)

Created on 2024-04-27 with reprex v2.1.0

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.3 (2024-02-29) #> os macOS Sonoma 14.4.1 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Europe/Berlin #> date 2024-04-27 #> pandoc 3.1.13 @ /usr/local/bin/ (via rmarkdown) #> quarto 1.5.29 @ /usr/local/bin/quarto #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> bayestestR 0.13.2 2024-02-12 [1] RSPM (R 4.3.0) #> bit 4.0.5 2022-11-15 [1] CRAN (R 4.3.0) #> bit64 4.0.5 2020-08-30 [1] CRAN (R 4.3.0) #> boot 1.3-30 2024-02-26 [1] RSPM (R 4.3.0) #> BWStest 0.2.3 2023-10-10 [1] CRAN (R 4.3.1) #> cachem 1.0.8 2023-05-01 [1] CRAN (R 4.3.0) #> cli 3.6.2.9000 2024-04-14 [1] Github (r-lib/cli@bcb5c78) #> coda 0.19-4.1 2024-01-31 [1] RSPM (R 4.3.0) #> codetools 0.2-20 2024-03-31 [1] RSPM (R 4.3.0) #> colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.0) #> correlation 0.8.5 2023-08-21 [1] https://easystats.r-universe.dev (R 4.3.1) #> crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) #> curl 5.2.1 2024-03-01 [1] RSPM (R 4.3.0) #> datawizard 0.10.0 2024-03-26 [1] RSPM (R 4.3.0) #> digest 0.6.35 2024-03-11 [1] RSPM (R 4.3.0) #> dplyr 1.1.4 2023-11-17 [1] RSPM (R 4.3.0) #> effectsize 0.8.7.1 2024-04-03 [1] https://easystats.r-universe.dev (R 4.3.3) #> emmeans 1.10.1 2024-04-06 [1] RSPM (R 4.3.0) #> estimability 1.5 2024-02-20 [1] RSPM (R 4.3.0) #> evaluate 0.23 2023-11-01 [1] CRAN (R 4.3.1) #> fansi 1.0.6 2023-12-08 [1] RSPM (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.4 2024-04-25 [1] RSPM (R 4.3.0) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0) #> ggplot2 3.5.1 2024-04-23 [1] CRAN (R 4.3.3) #> ggrepel 0.9.5 2024-01-10 [1] RSPM (R 4.3.0) #> ggsignif 0.6.4 2022-10-13 [1] CRAN (R 4.3.0) #> ggstatsplot * 0.12.3 2024-04-06 [1] RSPM (R 4.3.0) #> glue 1.7.0 2024-01-09 [1] RSPM (R 4.3.0) #> gmp 0.7-4 2024-01-15 [1] RSPM (R 4.3.0) #> gtable 0.3.5 2024-04-22 [1] RSPM (R 4.3.0) #> highr 0.10 2022-12-22 [1] CRAN (R 4.3.0) #> hms 1.1.3 2023-03-21 [1] CRAN (R 4.3.0) #> htmltools 0.5.8.1 2024-04-04 [1] RSPM (R 4.3.0) #> insight 0.19.10 2024-03-22 [1] RSPM (R 4.3.0) #> knitr 1.46 2024-04-06 [1] RSPM (R 4.3.0) #> kSamples 1.2-10 2023-10-07 [1] CRAN (R 4.3.1) #> labeling 0.4.3 2023-08-29 [1] CRAN (R 4.3.0) #> lattice 0.22-6 2024-03-20 [1] RSPM (R 4.3.0) #> lifecycle 1.0.4 2023-11-07 [1] RSPM (R 4.3.0) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) #> MASS 7.3-60.0.1 2024-01-13 [1] CRAN (R 4.3.3) #> Matrix 1.6-5 2024-01-11 [1] CRAN (R 4.3.3) #> memoise 2.0.1 2021-11-26 [1] CRAN (R 4.3.0) #> multcomp 1.4-25 2023-06-20 [1] CRAN (R 4.3.0) #> multcompView 0.1-10 2024-03-08 [1] RSPM (R 4.3.0) #> munsell 0.5.1 2024-04-01 [1] RSPM (R 4.3.0) #> mvtnorm 1.2-4 2023-11-27 [1] RSPM (R 4.3.0) #> paletteer 1.6.0 2024-01-21 [1] RSPM (R 4.3.0) #> parameters 0.21.6.2 2024-04-05 [1] https://easystats.r-universe.dev (R 4.3.3) #> patchwork 1.2.0 2024-01-08 [1] RSPM (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.10 2023-12-10 [1] RSPM (R 4.3.0) #> prismatic 1.1.2 2024-04-10 [1] RSPM (R 4.3.0) #> purrr 1.0.2 2023-08-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.26.0 2024-01-24 [1] RSPM (R 4.3.0) #> R.utils 2.12.3 2023-11-18 [1] RSPM (R 4.3.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) #> Rcpp 1.0.12 2024-01-09 [1] RSPM (R 4.3.0) #> readr 2.1.5 2024-01-10 [1] RSPM (R 4.3.0) #> rematch2 2.1.2 2020-05-01 [1] CRAN (R 4.3.0) #> reprex 2.1.0 2024-01-11 [1] RSPM (R 4.3.0) #> rlang 1.1.3 2024-01-10 [1] RSPM (R 4.3.0) #> rmarkdown 2.26 2024-03-05 [1] RSPM (R 4.3.2) #> Rmpfr 0.9-5 2024-01-21 [1] RSPM (R 4.3.0) #> rstudioapi 0.16.0 2024-03-24 [1] RSPM (R 4.3.0) #> sandwich 3.1-0 2023-12-11 [1] RSPM (R 4.3.0) #> scales 1.3.0 2023-11-28 [1] RSPM (R 4.3.2) #> sessioninfo 1.2.2.9000 2024-04-21 [1] Github (r-lib/sessioninfo@064bc38) #> statsExpressions 1.5.4 2024-03-20 [1] RSPM (R 4.3.0) #> styler 1.10.3 2024-04-07 [1] RSPM (R 4.3.0) #> SuppDists 1.1-9.7 2022-01-03 [1] CRAN (R 4.3.0) #> survival 3.6-4 2024-04-24 [1] RSPM (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.1 2024-01-24 [1] RSPM (R 4.3.0) #> tidyselect 1.2.1 2024-03-11 [1] RSPM (R 4.3.0) #> tzdb 0.4.0 2023-05-12 [1] CRAN (R 4.3.0) #> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.3.1) #> vctrs 0.6.5 2023-12-01 [1] RSPM (R 4.3.0) #> vroom 1.6.5 2023-12-05 [1] RSPM (R 4.3.0) #> withr 3.0.0 2024-01-16 [1] RSPM (R 4.3.0) #> xfun 0.43 2024-03-25 [1] RSPM (R 4.3.0) #> xml2 1.3.6 2023-12-04 [1] RSPM (R 4.3.0) #> xtable 1.8-4 2019-04-21 [1] CRAN (R 4.3.0) #> yaml 2.3.8 2023-12-11 [1] RSPM (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 #> * ── Packages attached to the search path. #> #> ────────────────────────────────────────────────────────────────────────────── ```
RainRam commented 6 months ago

SORRY I use this parameter set: digits = "signif3" (you can reproduce via this) rather than digits = "scientific1"

IndrajeetPatil commented 6 months ago

Still same:

library(ggstatsplot)

ggs_exp <- readr::read_csv("/Users/indrajeetpatil/Downloads/ggs_exp.csv")

ggbetweenstats(
  x = x,
  y = y,
  data = ggs_exp,
  type = "np",
  digits = "signif3"
)

Created on 2024-04-27 with reprex v2.1.0

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.3 (2024-02-29) #> os macOS Sonoma 14.4.1 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Europe/Berlin #> date 2024-04-27 #> pandoc 3.1.13 @ /usr/local/bin/ (via rmarkdown) #> quarto 1.5.29 @ /usr/local/bin/quarto #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> bayestestR 0.13.2 2024-02-12 [1] RSPM (R 4.3.0) #> bit 4.0.5 2022-11-15 [1] CRAN (R 4.3.0) #> bit64 4.0.5 2020-08-30 [1] CRAN (R 4.3.0) #> boot 1.3-30 2024-02-26 [1] RSPM (R 4.3.0) #> BWStest 0.2.3 2023-10-10 [1] CRAN (R 4.3.1) #> cachem 1.0.8 2023-05-01 [1] CRAN (R 4.3.0) #> cli 3.6.2.9000 2024-04-14 [1] Github (r-lib/cli@bcb5c78) #> coda 0.19-4.1 2024-01-31 [1] RSPM (R 4.3.0) #> codetools 0.2-20 2024-03-31 [1] RSPM (R 4.3.0) #> colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.0) #> correlation 0.8.5 2023-08-21 [1] https://easystats.r-universe.dev (R 4.3.1) #> crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) #> curl 5.2.1 2024-03-01 [1] RSPM (R 4.3.0) #> datawizard 0.10.0 2024-03-26 [1] RSPM (R 4.3.0) #> digest 0.6.35 2024-03-11 [1] RSPM (R 4.3.0) #> dplyr 1.1.4 2023-11-17 [1] RSPM (R 4.3.0) #> effectsize 0.8.7.1 2024-04-03 [1] https://easystats.r-universe.dev (R 4.3.3) #> emmeans 1.10.1 2024-04-06 [1] RSPM (R 4.3.0) #> estimability 1.5 2024-02-20 [1] RSPM (R 4.3.0) #> evaluate 0.23 2023-11-01 [1] CRAN (R 4.3.1) #> fansi 1.0.6 2023-12-08 [1] RSPM (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.4 2024-04-25 [1] RSPM (R 4.3.0) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0) #> ggplot2 3.5.1 2024-04-23 [1] CRAN (R 4.3.3) #> ggrepel 0.9.5 2024-01-10 [1] RSPM (R 4.3.0) #> ggsignif 0.6.4 2022-10-13 [1] CRAN (R 4.3.0) #> ggstatsplot * 0.12.3 2024-04-06 [1] RSPM (R 4.3.0) #> glue 1.7.0 2024-01-09 [1] RSPM (R 4.3.0) #> gmp 0.7-4 2024-01-15 [1] RSPM (R 4.3.0) #> gtable 0.3.5 2024-04-22 [1] RSPM (R 4.3.0) #> highr 0.10 2022-12-22 [1] CRAN (R 4.3.0) #> hms 1.1.3 2023-03-21 [1] CRAN (R 4.3.0) #> htmltools 0.5.8.1 2024-04-04 [1] RSPM (R 4.3.0) #> insight 0.19.10 2024-03-22 [1] RSPM (R 4.3.0) #> knitr 1.46 2024-04-06 [1] RSPM (R 4.3.0) #> kSamples 1.2-10 2023-10-07 [1] CRAN (R 4.3.1) #> labeling 0.4.3 2023-08-29 [1] CRAN (R 4.3.0) #> lattice 0.22-6 2024-03-20 [1] RSPM (R 4.3.0) #> lifecycle 1.0.4 2023-11-07 [1] RSPM (R 4.3.0) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) #> MASS 7.3-60.0.1 2024-01-13 [1] CRAN (R 4.3.3) #> Matrix 1.6-5 2024-01-11 [1] CRAN (R 4.3.3) #> memoise 2.0.1 2021-11-26 [1] CRAN (R 4.3.0) #> multcomp 1.4-25 2023-06-20 [1] CRAN (R 4.3.0) #> multcompView 0.1-10 2024-03-08 [1] RSPM (R 4.3.0) #> munsell 0.5.1 2024-04-01 [1] RSPM (R 4.3.0) #> mvtnorm 1.2-4 2023-11-27 [1] RSPM (R 4.3.0) #> paletteer 1.6.0 2024-01-21 [1] RSPM (R 4.3.0) #> parameters 0.21.6.2 2024-04-05 [1] https://easystats.r-universe.dev (R 4.3.3) #> patchwork 1.2.0 2024-01-08 [1] RSPM (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.10 2023-12-10 [1] RSPM (R 4.3.0) #> prismatic 1.1.2 2024-04-10 [1] RSPM (R 4.3.0) #> purrr 1.0.2 2023-08-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.26.0 2024-01-24 [1] RSPM (R 4.3.0) #> R.utils 2.12.3 2023-11-18 [1] RSPM (R 4.3.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) #> Rcpp 1.0.12 2024-01-09 [1] RSPM (R 4.3.0) #> readr 2.1.5 2024-01-10 [1] RSPM (R 4.3.0) #> rematch2 2.1.2 2020-05-01 [1] CRAN (R 4.3.0) #> reprex 2.1.0 2024-01-11 [1] RSPM (R 4.3.0) #> rlang 1.1.3 2024-01-10 [1] RSPM (R 4.3.0) #> rmarkdown 2.26 2024-03-05 [1] RSPM (R 4.3.2) #> Rmpfr 0.9-5 2024-01-21 [1] RSPM (R 4.3.0) #> rstudioapi 0.16.0 2024-03-24 [1] RSPM (R 4.3.0) #> sandwich 3.1-0 2023-12-11 [1] RSPM (R 4.3.0) #> scales 1.3.0 2023-11-28 [1] RSPM (R 4.3.2) #> sessioninfo 1.2.2.9000 2024-04-21 [1] Github (r-lib/sessioninfo@064bc38) #> statsExpressions 1.5.4 2024-03-20 [1] RSPM (R 4.3.0) #> styler 1.10.3 2024-04-07 [1] RSPM (R 4.3.0) #> SuppDists 1.1-9.7 2022-01-03 [1] CRAN (R 4.3.0) #> survival 3.6-4 2024-04-24 [1] RSPM (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.1 2024-01-24 [1] RSPM (R 4.3.0) #> tidyselect 1.2.1 2024-03-11 [1] RSPM (R 4.3.0) #> tzdb 0.4.0 2023-05-12 [1] CRAN (R 4.3.0) #> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.3.1) #> vctrs 0.6.5 2023-12-01 [1] RSPM (R 4.3.0) #> vroom 1.6.5 2023-12-05 [1] RSPM (R 4.3.0) #> withr 3.0.0 2024-01-16 [1] RSPM (R 4.3.0) #> xfun 0.43 2024-03-25 [1] RSPM (R 4.3.0) #> xml2 1.3.6 2023-12-04 [1] RSPM (R 4.3.0) #> xtable 1.8-4 2019-04-21 [1] CRAN (R 4.3.0) #> yaml 2.3.8 2023-12-11 [1] RSPM (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 #> * ── Packages attached to the search path. #> #> ────────────────────────────────────────────────────────────────────────────── ```
RainRam commented 6 months ago

doesn't matter, the matter thing is how to express the p values without "e" form such as 2.81e-16, just presenting them with solely number, for example, 0.xxx (a actural number when the value > 0.001) or < 0.001(when the value < 0.001), am I clear? can it be achieved?

thank you for your warm feedback and quick response