title: How to put the legends in the peaks of multiple distributions using ggplot?
body: <p>I want to place the legend of each histogram over its peak instead of the right of the figure in R. Let me explain it with a pseudo data set:</p>
  
  <pre><code>a &lt;- rnorm(100, mean = 20, sd = 1)
  b &lt;- rnorm(100, mean = 22, sd = 1)
  aleg &lt;- rep("A",length(a))
  bleg &lt;- rep("B",length(b))
  data &lt;- data.frame(value=c(a,b), variable=c(lega,legb))
  ggplot(data,aes(x=value, fill=variable)) + geom_density(alpha=0.25) + labs(fill="")
  </code></pre>
  
  <p>which gives you:</p>
  
  <p><a href="https://i.stack.imgur.com/rGowO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rGowO.png" alt="enter image description here"></a></p>
  
  <p>This is what I want:</p>
  
  <p><a href="https://i.stack.imgur.com/4MEf3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4MEf3.png" alt="enter image description here"></a></p>
  
  <p>I have a big data set that has ~8 different variables. That's why I want a quick solution instead of adding individual text boxes.</p>
  
  <p>Thanks in advance!</p>