I'm trying to do a pairwise comparison of grouped data. I've used stat_compare_means to do this successfully before, but for some reason this time it is only showing the comparison bars in one of the facet panels. I've tried, but can't seem to make it work. I've provided a simplified worked example below with just two conditions below. The real data has the same number of sets, but more conditions. Any help much appreciated!
data <- data.frame(sample = seq(1:83),
condition = c("KO", "KO", "KO", "KO", "KO", "KO", "KO", "KO", "KO", "KO",
"KO", "KO", "KO", "KO", "KO", "KO", "KO", "WT", "WT", "WT", "WT",
"WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT",
"WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT",
"WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT",
"WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT",
"WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT",
"WT", "WT", "WT", "WT", "WT", "WT", "WT"),
set = c("di", "tet", "mono", "di", "tet", "di", "tet", "mono", "di",
"tet", "mono", "di", "tet", "mono", "di", "tet", "mono", "di",
"tet", "mono", "di", "tet", "mono", "di", "tet", "mono", "di",
"tet", "mono", "di", "tet", "mono", "di", "tet", "mono", "di",
"tet", "mono", "di", "tet", "mono", "di", "tet", "mono", "di",
"tet", "mono", "di", "tet", "mono", "di", "tet", "mono", "di",
"tet", "mono", "di", "tet", "mono", "di", "tet", "mono", "di",
"tet", "mono", "di", "tet", "mono", "di", "tet", "mono", "di",
"tet", "mono", "di", "tet", "mono", "di", "tet", "mono", "di",
"tet", "mono"),
score = c(0, 0, 0, -5.95940584704586, 10.0932562947815, -3.16676604569923,
4.46133814098881, -1.9888611720281, -7.08194974795108, 3.17097628218171,
-1.83986980857496, -0.843268716519414, 1.40178526106758, -0.340339302553342,
-3.76913603338144, 4.28943971347741, -3.20197704274428, -3.54168755452774,
15.414510676737, -5.85333426479177, -1.87949902971026, 14.1424002410594,
-2.14726619139082, -5.01378228438499, 11.1131227496058, 0.097013584879446,
-6.55527134311774, 12.2234175105232, -2.55259067519978, -6.68392512983342,
15.8358484731832, -2.27825891764331, -5.40451835097939, 11.2240240941934,
-1.53075128507785, -4.80008896082703, 15.3667539728667, -4.81370852797055,
-2.69976280917806, 21.9926791189896, 0.61798090190648, -8.68663007652496,
13.8852585926079, -0.80329005076484, -16.8459570277756, 13.3500356549569,
-5.59531483186873, -3.33602772657725, 11.338954967882, -2.12614700145763,
-3.37418493461362, 11.5903340330526, -2.87224785160433, -14.7792521265679,
7.7542705233175, -2.06876649679246, -1.31032740187699, 17.6666627835987,
-0.824420163207606, -4.82659116096503, -0.0626028094479509, -1.90431942338018,
-20.3180652520285, 6.83632028067972, -1.58570945276274, -2.77261532150261,
2.98168865160908, -1.89922364414076, -5.80584721371712, 7.13599592922731,
-1.23964885854847, -5.1236580504364, 14.5532078112838, -3.82017971494402,
-4.39741499313133, 11.7342969461195, -2.5852194454582, -3.18458897513284,
12.7762556862722, 1.1245622869403, -2.98430760077172, 13.981837061262,
-1.19532384849617))
ggplot(data aes(x=condition, y=score, fill=set)) +
stat_summary(fun=mean, geom="bar", colour="black", alpha=1) +
stat_summary(fun.data = mean_se, geom = "errorbar", width=0.25) +
geom_point(color="black", shape=21, show.legend=TRUE, size=3, stroke=1) +
facet_wrap(~set, scales="free") +
stat_compare_means(method = "t.test", comparisons=list(c("KO", "WT")), hide.ns=F) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_y_continuous(expand = expansion(mult = c(0.2, 0.2)))