title: Add means to histograms by group in ggplot2
body: <p>I am following <a href="https://r-charts.com/distribution/histogram-group-ggplot2/" rel="nofollow noreferrer">this source</a> to do histograms by group in <code>ggplot2</code>.</p>
  <p>The sample data looks like this:</p>
  <pre><code> set.seed(3)
  x1 &lt;- rnorm(500)
  x2 &lt;- rnorm(500, mean = 3)
  x &lt;- c(x1, x2)
  group &lt;- c(rep(&quot;G1&quot;, 500), rep(&quot;G2&quot;, 500))
  
  df &lt;- data.frame(x, group = group)
  </code></pre>
  <p>And the code:</p>
  <pre><code># install.packages(&quot;ggplot2&quot;)
  library(ggplot2)
  
  # Histogram by group in ggplot2
  ggplot(df, aes(x = x, fill = group, colour = group)) + 
    geom_histogram(alpha = 0.5, position = &quot;identity&quot;)
  </code></pre>
  <p>I know that adding a line like:</p>
  <pre><code>  +geom_vline(aes(xintercept=mean(group),color=group,fill=group), col = &quot;red&quot;)
  </code></pre>
  <p>Should allow me to get what I am looking for, but I am obtaining just an histogram with one mean, not a mean by group:
  <a href="https://i.stack.imgur.com/bHR7Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bHR7Z.png" alt="Histogram" /></a></p>
  <p>Do you have any suggestions?</p>