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

Possible to use stat_pvalue_manual() with dodged bar chart? #104

Closed
emcnerny opened this issue Jul 28, 2018 · 3 comments
Closed

Possible to use stat_pvalue_manual() with dodged bar chart? #104

emcnerny opened this issue Jul 28, 2018 · 3 comments

Comments

@emcnerny
Copy link

Is there any way to define the group names (columns 'group1' and 'group2' in the df) so that the new stat_pvalue_manual function can map the comparisons to specific bars on a dodged bar chart with grouping factors for both x and color?

@kassambara
Copy link
Owner

Please, try this:

library(rstatix)  # https://github.com/kassambara/rstatix
stat.test <- ToothGrowth %>%
  group_by(dose) %>%
  t_test(len ~ supp) %>%
  adjust_pvalue() %>%
  add_significance("p.adj")


library("ggpubr")
ggbarplot(ToothGrowth, x = "dose", y = "len", add = "mean_se",
          color = "supp", palette = "jco", 
          position = position_dodge(0.8)) +
  stat_pvalue_manual(stat.test, x= "dose", y.position = 30, label = "p = {p.adj}")

rplot

@Adam-JJJJJ
Copy link

Adam-JJJJJ commented May 26, 2019

Please, try this:

library(rstatix)  # https://github.com/kassambara/rstatix
stat.test <- ToothGrowth %>%
  group_by(dose) %>%
  t_test(len ~ supp) %>%
  adjust_pvalue() %>%
  add_significance("p.adj")


library("ggpubr")
ggbarplot(ToothGrowth, x = "dose", y = "len", add = "mean_se",
          color = "supp", palette = "jco", 
          position = position_dodge(0.8)) +
  stat_pvalue_manual(stat.test, x= "dose", y.position = 30, label = "p = {p.adj}")

rplot

Hi,Doc, thanks for your codes. May i ask that if i have three columns(three "supp")per "dose", for instance, i compared treatment 1 and 2, 1 and 3, respectively, how can i separate the two different t.test results? In my results, two t.test results was stacked in the treatment 2 (because the treatment 2 was the middle column), how can i separate two results above the two columns (treatment 2 and 3)?
image
I've tried position=position_dodge(0.9)in stat_pvalue_manual, but it did't seem to work. How to set position in stat_pvalue_manual?
Thank for ur time.

@kassambara
Copy link
Owner

kassambara commented May 29, 2019

fixed now, thanks!

Please install the latest dev version and try the R code below:

df <- ToothGrowth
df$dose <- as.factor(df$dose)
# t - test
library(rstatix)  # https://github.com/kassambara/rstatix
stat.test <- df %>%
  group_by(supp) %>%
  t_test(len ~ dose, ref.group = "0.5") %>%
  adjust_pvalue() %>%
  add_significance("p.adj")
stat.test

# Plot
bp <- ggbarplot(df, x = "supp", y = "len",
                fill = "dose",
                add = "mean_sd", add.params = list(group = "dose"),
                position = position_dodge(0.8)) 
bp
# Add pvalue
bp + stat_pvalue_manual(
  stat.test, x = "supp", y.position = 33,
  label = "p.adj.signif",
  position = position_dodge(0.8)
)

Rplot

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