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

Can I provide my own stats to stat_compare_means #99

Closed
ml3958 opened this issue Jul 3, 2018 · 3 comments
Closed

Can I provide my own stats to stat_compare_means #99

ml3958 opened this issue Jul 3, 2018 · 3 comments

Comments

@ml3958
Copy link

ml3958 commented Jul 3, 2018

Hello!

thanks for developing ggpubr. Stat_compare_means is particular awesome to add stats onto ggplot2 beautifully.

However, I wondering is there a way to put a subset of compare_means() output object onto my ggplot2? I couldn't do it with stat_compare_means, for that it would change the p-values by assuming less comparisons than supposed, while more comparisons are done and I just want to plot subset of the statistics.

Can this be done easily somehow? Any insight would be helpful.

Thanks

@kassambara
Copy link
Owner

To add manually a p-value onto a ggplot2,

  • First, install the latest developmental version of ggpubr
  • then, use the function stat_pvalue_manual()
library("dplyr")
library("ggpubr")

# Pairwise t-test between groups
stat.test <- compare_means(
  len ~ dose, data = ToothGrowth,
  method = "t.test"
) %>%
  mutate(y.position = c(29, 35, 39))
stat.test
# A tibble: 3 x 9
    .y. group1 group2            p   p.adj p.format p.signif method y.position
                                 
1   len    0.5      1 1.268301e-07 2.5e-07  1.3e-07     **** T-test         29
2   len    0.5      2 4.397525e-14 1.3e-13  4.4e-14     **** T-test         35
3   len      1      2 1.906430e-05 1.9e-05  1.9e-05     **** T-test         39
# Create a box plot and add the p-value
ggboxplot(ToothGrowth, x = "dose", y = "len") +
  stat_pvalue_manual(
    data = stat.test, label = "p.adj",
    xmin = "group1", xmax = "group2",
    y.position = "y.position"
    )

rplot

@ml3958
Copy link
Author

ml3958 commented Jul 10, 2018

Awesome! thanks

@kassambara
Copy link
Owner

so we can close this issue...

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

2 participants