Adding texts to boxplot - ggplot2

Viewed 207

enter image description here

I would like to manually add text to indicate significant differences on my graphs by adding letters (e.g. a, b and c) over specific locations on my boxplot using ggplot2. So essentially, I want to be able to add text where I want on the plot.

I have added an example of a graph in the picture above. I have entered the letters (a,b,c) manually in Microsoft Word but I would like to be able to do this in R. Can someone please help? Thank you

3 Answers

use ggplot(...) + geom_text() from ggplot2.

just add this line to your code:

annotate("text", x = 3, y=10, label = "whatever")
 

Alternatively, you can try this. "Data" and "variable" are just names for what you would put in:

ggplot(data,aes(x=variable))+
    geom_boxplot(aes(y=variable2),color="variable")
Related