title: how can I plot a histogramme with y axis representing proportion of observations in a bin with geom_histogram?
body: <p>I would like to plot a histogramme, whereby the y axis shows the proportion of observation in the bin. I tried to use the code as suggested here</p>
  
  <p><a href="https://ggplot2.tidyverse.org/reference/geom_histogram.html" rel="nofollow noreferrer">https://ggplot2.tidyverse.org/reference/geom_histogram.html</a></p>
  
  <pre><code>ggplot(data=diamonds, aes(x=carat, after_stat(density))) +  geom_histogram(binwidth = 0.05, position="identity", fill =  "white", colour = "black") 
  </code></pre>
  
  <p>and here </p>
  
  <p><a href="https://stackoverflow.com/questions/22181132/normalizing-y-axis-in-histograms-in-r-ggplot-to-proportion-by-group">Normalizing y-axis in histograms in R ggplot to proportion by group</a></p>
  
  <pre><code>ggplot(data=diamonds, aes(x=carat)) +  geom_histogram(aes(y=..density..), binwidth = 0.05, position="identity", fill =  "white", colour = "black") 
  </code></pre>
  
  <p>but the y axis range is higher than 1 in both cases. </p>
  
  <p><a href="https://i.stack.imgur.com/Ud7tE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ud7tE.png" alt="enter image description here"></a></p>
  
  <p>Also when I decrease the binwidth the range of y axis (i.e. the proportion in the most represented group) becomes higher, which does not make any sense, since the group sizes should decrease if I increase the number of groups.</p>