As the title says, can ggplot2 display the calculated boxplot values as labels? I would like the max, upper hinge, median, lower hinge, and min values displayed.
With the simple example of:
ggplot()+
geom_boxplot(data = mtcars,
aes(group = cyl,
x = gear, y = mpg))
I understand that I could calculate these values with something simple like the following and call the calculated values to get the following graph, but my data is much more complex and difficult to calculate the values as such.
mtcarsProbs <- mtcars %>%
group_by(cyl) %>%
summarise(min = quantile(mpg, probs = 0),
`25th` = quantile(mpg, probs = 0.25),
median = quantile(mpg, probs = 0.5),
`75th` = quantile(mpg, probs = 0.75),
max = quantile(mpg, probs = 1))
ggplot()+
geom_boxplot(data = mtcars,
aes(group = cyl,
x = cyl, y = mpg))+
geom_text(data = mtcarsProbs,
aes(x = cyl, y = max+1,
label = max))+
geom_text(data = mtcarsProbs,
aes(x = cyl, y = `75th`-0.5,
label = `75th`))+
geom_text(data = mtcarsProbs,
aes(x = cyl, y = median+0.5,
label = median))+
geom_text(data = mtcarsProbs,
aes(x = cyl, y = `25th`+0.5,
label = `25th`))+
geom_text(data = mtcarsProbs,
aes(x = cyl, y = min-1,
label = min))