I want to add text to indicate the median and hinges in a boxplot (left or right of the box). I am struggling with the horizontal positioning of the text. How can I calculate the x coordinates of the box (left and right)? (or how can I position them adequately to the left or right of the box).
set.seed(0)
d <- data.frame(x = rnorm(20))
pos <- quantile(d$x)[2:4]
s <- data.frame(pos, q=names(pos))
ggplot(d, aes("A", x)) +
geom_boxplot() +
geom_text(aes(y=pos, label=q), s, hjust=5)