If I have the following dataframe, organised by type and subtype:
df = rbind(
data.frame(type="A", subtype="c", value=rnorm(mean=1, 100)),
data.frame(type="B", subtype="c", value=rnorm(mean=1.5, 100)),
data.frame(type="A", subtype="d", value=rnorm(mean=2, 100)),
data.frame(type="B", subtype="d", value=rnorm(mean=2.5, 100))
)
And I create a box plot as per below:
p = ggplot(df, aes(x=type, y=value, color=subtype)) +
geom_boxplot(outlier.shape = NA)
I know that I can add significance bars between the subtypes of each type (I.e. Between A.c and A.d, and then also between B.c and B.d) by doing the following:
p + ggpubr::stat_compare_means(test = 'wilcox.test', label = 'p.signif', show.legend = F)
How can I add significance bars between select columns? E.g. If I want to add a significance bar between A.c and B.c how can I do this? Is there some way that I can call the columns?
The comparisons parameter of the ggpubr::stat_compare_means function apparently takes in column indexes, but I can't figure out how to reference the subtype indexes.
I want something that looks like the following:



