title: How to add labels to each bar of my histogram in ggplot2?
body: <p>I'm currently making a histogram in R using ggplot2. I want to add the y value of my histogram (which is the percentage of the total) for each bar in my histogram (or at least the first 5 bars). I've tried to replicate examples I've seen here without success.</p>
  <p>Here's my code.</p>
  <pre><code>df_2 %&gt;%
    ggplot(aes(x = day_difference)) +
    geom_histogram(aes(y = stat(count)/sum(stat(count))), color=&quot;darkblue&quot;, fill=&quot;deepskyblue2&quot;, binwidth = 10, boundary = 9) +
    stat_bin(binwidth = 10, geom=&quot;text&quot;, colour=&quot;black&quot;, size=3.5, aes(label=stat(count)/sum(stat(count)))) +
    scale_x_continuous(breaks = breaks_width(10)) +
    scale_y_continuous(labels = percent, breaks = breaks_width(0.1)) +
    labs(x = &quot;difference (days)&quot;, y = &quot;count&quot;, title = &quot;Difference between first and second invitations (2021)&quot;) +
    theme_bw()
  </code></pre>
  <p>When doing this, my result is:</p>
  <p><img src="https://i.stack.imgur.com/Luj6q.png" alt="img" /></p>
  <p>Basically, it seems like the labels are actually okay since it follows my histogram's distribution (I now will multiply by 100 to get the percentage and round it).. The problem is everything else, as you can see in the picture the plot isn't created and it feels like all the bars are stacked at the left.</p>
  <p>Is there any way to solve this? It also takes a lot of time, while my plots usually take some seconds to be created. Thanks.</p>