-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report p-values as <0.001 (or similar) #186
Comments
good idea and thank you for the well documented examples. I will implement this as soon as possible |
Hi, With the current version, you can pass any pvalue formatting function you want to For example: # Custom formatting fucntion
format_pval <- function(pval){
pval <- scales::pvalue(pval, accuracy= 0.0001, add_p = TRUE)
gsub(pattern = "(=|<)", replacement = " \\1 ", x = pval)
}
# Display formatted p-value
ggscatter(mtcars, x = "wt", y = "mpg", add = "reg.line") +
stat_cor(
aes(label = paste(..rr.label.., format_pval(..p..), sep = "~`,`~")),
label.x = 3
) |
Thanks! |
Is it possible to avoid the space between the R2 value and comma? |
You can use library(ggpubr)
# Custom formatting fucntion
format_pval <- function(pval){
pval <- scales::pvalue(pval, accuracy= 0.0001, add_p = TRUE)
gsub(pattern = "(=|<)", replacement = " \\1 ", x = pval)
}
# Display formatted p-value
ggscatter(mtcars, x = "wt", y = "mpg", add = "reg.line") +
stat_cor(
aes(label = paste(..rr.label.., format_pval(..p..), sep = "*`,`~")),
label.x = 3
)
|
With the latest dev version, you can now specify the argument suppressPackageStartupMessages(library(ggpubr))
# Default plot
sp <- ggscatter(mtcars, x = "wt", y = "mpg", add = "reg.line")
sp + stat_cor(label.x = 3)
#> `geom_smooth()` using formula 'y ~ x' # Specify the number of decimal places of precision for
# the p-value and the correlation coefficient r
sp + stat_cor(label.x = 3, p.accuracy = 0.001, r.accuracy = 0.01)
#> `geom_smooth()` using formula 'y ~ x' Created on 2020-05-10 by the reprex package (v0.3.0.9001) |
This is fantastic, but is it true that this functionality is not available for stat_compare_means()? It would be fantastic to be able to do the same p-value formatting throughout statistical tests and procedures in ggpubr. |
Any updates on adding |
It would be great to have an option to report small p-values at some arbitrary threshold, e.g. "p < 0.001" or "p < 0.0001" . Looks like some efforts along this path exist in
stat_cor()
but it is hardcoded and at machine level precision.I'm thinking that instead of this:
You might be able to implement something like this:
where
accuracy
defines how far the p-value rounding went, much like thepvalue_format()
function from the scales package does. I.e.I note that you've used spaces around the
=
and<
in the ggpubr package, so that could be added back in:The text was updated successfully, but these errors were encountered: