Skip to content
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

hide.NS option for add_pvalue function #7

Open
jaydoc opened this issue Apr 5, 2021 · 4 comments
Open

hide.NS option for add_pvalue function #7

jaydoc opened this issue Apr 5, 2021 · 4 comments

Comments

@jaydoc
Copy link

jaydoc commented Apr 5, 2021

This is an option in stat_pvalue_manual to hide insignificant p values from being plotted and seems to be missing from add_pvalue function. Would you be able to add it?

@csdaw
Copy link
Owner

csdaw commented Apr 5, 2021

Hi there. I left out this option on purpose as it assumed that your significance level would always be 0.05, which might not always be the case.

I felt it was better to just filter out the non-significant rows from the p-value data.frame before plotting, as below:

library(ggplot2)
library(ggprism)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

df_p_val <- ToothGrowth %>%
  rstatix::group_by(dose) %>%
  rstatix::t_test(len ~ supp) %>%
  rstatix::adjust_pvalue(p.col = "p", method = "bonferroni") %>%
  rstatix::add_significance(p.col = "p.adj") %>% 
  rstatix::add_xy_position(x = "dose", dodge = 0.8) %>%
  filter(p.adj < 0.01)          # here we have chosen an alpha of 0.01

p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) + 
  geom_boxplot(aes(fill = supp)) + 
  theme_prism() + 
  coord_cartesian(ylim = c(0, 40))

p + add_pvalue(df_p_val, 
               xmin = "xmin", 
               xmax = "xmax",
               label = "p = {p.adj}",
               tip.length = 0)

Created on 2021-04-05 by the reprex package (v1.0.0)

@jaydoc
Copy link
Author

jaydoc commented Apr 6, 2021

I can see why you left it out.

In my use case, I am using add_pvalue as part of a function in which I am providing custom y.position values as a vector of values calculated on-the-fly when the function is called.

If I filter the p-values it creates errors regarding vector lengths and 'list' object cannot be coerced to type 'double'.

I will try to provide a MWE if required.

@csdaw
Copy link
Owner

csdaw commented Apr 6, 2021

Yes a MWE would be helpful :) I expect there is a mismatch between the length of y.position and the nrow ofdata.

As a side note, looking at the source for stat_pvalue_manual(), the hide.ns option calls the internal remove_ns() function which just uses dplyr::filter() as well so it shouldn't function any differently to just filtering beforehand.

@dannychu1108
Copy link

Hi! I'm trying to use your method to filter out the ns values, but I received an error:
Error:
! Problem while computing aesthetics.
ℹ Error occurred in the 4th layer.
Caused by error in check_aesthetics():
! Aesthetics must be either length 1 or the same as the data (1)
✖ Fix the following mappings: fill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants