How can I calculate the maximum histogram value when making a plot?
I want to place a line on a plot with an annotation, and I want the text to be position proportional to the y-axis max value. For example:
library(ggplot2)
df <- data.frame(x = runif(1000))
p <- ggplot(data=df, aes(x)) + geom_histogram()
p + geom_vline(aes(xintercept=0.5),color='red') + geom_text(aes(0.55, 10, label='line'), angle = 90, color='red')
produces the following:

I would like to pass an argument to geom_text() which is 1/3 of the max histogram value as I think this is the best way of positioning the text consistently, but I don’t know how to calculate this count value.
stat_binuses binwidth=range/30 by default. I’m not sure exactly how it’s calculated but this should be a fairly reasonable approximation: