3

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)

enter image description here

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.

4
  • Can you clarify what you mean by differences between fill? Perhaps difference in the mean values? Commented Nov 3, 2015 at 20:27
  • I tried to rephrase above. I'm looking for a general solution to compare, for each x, the two groups defined by fill. An easy example would be to report p-values for difference in carat within each cut above. Commented Nov 3, 2015 at 21:15
  • Have you tried with 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 (the geom_text is basically the same in both cases). Commented Nov 3, 2015 at 21:42
  • Though I don't think I've seen an answer using 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. Commented Nov 3, 2015 at 21:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.