I can easily create grouped box plots from the diamonds data set:
dd = diamonds[diamonds$color %in% c("E","J"),]
ggplot(dd, aes(x=cut, y=carat)) +
geom_boxplot(aes(fill=color), outlier.shape=NA)
# note: below does *not* work for `geom_text()`
ggplot(dd, aes(x=cut, y=carat, fill=color)) +
geom_boxplot(outlier.shape=NA)
How can I label each x group defined by the fill variable?
I am looking for a solution using stat_summary() between each x pair, to compute e.g. the p-value between each red and green pair below
This roughly corresponds to this question, but the difference is that here the data is grouped by fill and I want to label those groups.

fill? Perhaps difference in themeanvalues?x, the two groups defined byfill. An easy example would be to report p-values for difference incaratwithin eachcutabove.geom_text()? It's a relatively common question: possible duplicates dupe 1, dupe 2, lots more if you can generalize from a dodged barplot: dupe 1, dupe 2, dupe 3 (thegeom_textis basically the same in both cases).stat_summary, so I think it would improve your question (and remove my temptation to close it as a duplicate) if you focus only on that possibility.