Hi I have a sample df as follows and I'm trying to perform t tests using the ggpubr
package with the stat_compare_means()
function however I cannot get it to compare across the groups that I want:
set.seed(13)
df = data.frame(grouping = c(rep("A",24),rep("B",24),rep("C",24)),
id = c(rep(1,12),rep(2,12),rep(3,12),rep(4,12),rep(5,12),rep(6,12)),
subject = c(rep(c("One","Two","Three","Four"),72)),
family = c(rep(c("Red","Red","Red","Red","Blue","Blue","Blue","Blue","Green","Green","Green","Green"),6)),
percent = sample(1:100,288,replace=T),
result = "Good")
df %>%
ggplot(aes(x=subject,y=percent,group = interaction(subject,grouping))) +
geom_boxplot(outlier.shape = NA) +
geom_point(aes(color = grouping),size=1.75,position = position_dodge(width = 0.75))+
scale_y_continuous(breaks = seq(0, 100, by = 25),limits = c(0,103)) +
facet_grid(result~family,switch = "y") +
scale_x_discrete("") +
theme_minimal() +
stat_compare_means(aes(group = grouping),label="p.signif",
method = "t.test",paired=F,
tip.length=0,step.increase = 0.05)
As seen from the picture it only has one "ns" for the statistical test but is it possible to have it for all three comparisons? I would want the tests to be between the grouping variable of A, B, and C so for example within the 3 boxplots of "Four" there would be 3 comparisons for A vs B, A vs C, and B vs C. I also tried adding comparisons = list(c("A","B"),c("A","C"),c("B","C"))
as the comparisons
argument but it also didn't work. Thanks a lot!