I am trying to adjust the position of comparison bars with stat_pvalue_manual. TL/DR How do I fix plot p1?
This is what I'm working with:
df <- ToothGrowth
grp<-rep(c("a","b","c"), 10)
df$grp <- grp
library(tidyverse)
library(rstatix)
stat.test_len <- df %>%
group_by(dose) %>%
dunn_test(len ~ supp)
stat.test_len <- stat.test_len %>% add_xy_position()
stat.test_len
# A tibble: 3 x 14
# dose .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif y.position
# <dbl> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr> <dbl>
#1 0.5 len OJ VC 10 10 -2.31 0.0210 0.0210 * 24.2
#2 1 len OJ VC 10 10 -2.91 0.00357 0.00357 ** 30.0
#3 2 len OJ VC 10 10 0.0379 0.970 0.970 ns 36.6
# ... with 3 more variables: groups <named list>, xmin <dbl>, xmax <dbl>
Now when I use it for ggplot, the xy positions don't adjust properly.
library(ggpubr)
p1 <- ggerrorplot(df, x = "dose", y = "len",
desc_stat = "mean_sd", color = "supp")+
stat_pvalue_manual(stat.test_len, label = "p.adj.signif",
tip.length = 0,
hide.ns = TRUE)
Somehow it still works when I use faceted plot.
p2 <- ggboxplot(df, x = "supp", y = "len", color = "supp")+
facet_wrap(~dose)+
stat_pvalue_manual(stat.test_len, label = "p.adj.signif",
tip.length = 0,
hide.ns = TRUE)
I added the extra column "grp" because that's what I need in my final plot. y-axis will be multiple doses. color will be 3 different values for grp. I need to plot stats for comparison between grp at each dose. Using the OG ToothGrowth df so that there are significant p-values to work with.
How do I fix plot p1?