I have below histogra musing ggplot
library(ggplot2)
n = 1000
mean = 0
sd = 1
binwidth = 0.3 # passed to geom_histogram and stat_function
set.seed(1)
df <- data.frame(x = rnorm(n, mean, sd))
myplot = ggplot(df, aes(x = x, mean = mean, sd = sd, binwidth = binwidth, n = n)) +
theme_bw() +
geom_histogram(binwidth = binwidth,
colour = "white", fill = "cornflowerblue", size = 0.1)
Now I want to add one custom label at the top-middl area, but there should be some margin, say 10 points at the top of my label. I tried below
myplot+
geom_label(aes(x = mean((df$x)), y = 100), label = 'Plot with y', label.padding = unit(.7, 'lines'), fill = '#000000', color = '#ffffff', alpha = 0.2)
Is there any way to dynamically (based on data only without any hardcoding) set y = 100
to keep the label at the top with 10 points margin?