I would like a label to appear above each box in a boxplot generated by ggplot2.
For example:
#Example data
test = c("A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B")
patient = c(1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3)
result = c(5, 7, 2 ,4, 6, 7, 3, 5, 5, 6, 2 ,3)
data <- tibble(test, patient, result)
#Labels I want to include
Alabs = c(1, 3, 500)
Blabs = c(8, 16, -32)
#Plot data
ggplot(data, aes(x = factor(patient), y = result, color = factor(test))) +
geom_boxplot(outlier.shape = 1)
Gives the plot:
I would like to print the first element of Alabs above the red box for the first patient, the second element of Alabs above the red box for the second patient, the first element of Blabs above the blue box for the first patient, etc.
How do I do this?


