Add legend to geom_vline
<p>I know that this question has been asked before but the solutions don't seem to work for me. </p>

<p>What I want to do is represent my median, mean, upper and lower quantiles on a histogram in different colours and then add a legend to the plot. This is what I have so far and I have tried to use <code>scale_color_manual</code> and <code>scale_color_identity</code> to give me a legend. Nothing seems to be working. </p>

<pre><code>quantile_1 &lt;- quantile(sf$Unit.Sales, prob = 0.25)
quantile_2 &lt;- quantile(sf$Unit.Sales, prob = 0.75)

ggplot(aes(x = Unit.Sales), data = sf) + 
  geom_histogram(color = 'black', fill = NA) + 
  geom_vline(aes(xintercept=median(Unit.Sales)),
            color="blue", linetype="dashed", size=1) + 
  geom_vline(aes(xintercept=mean(Unit.Sales)),
            color="red", linetype="dashed", size=1) +
  geom_vline(aes(xintercept=quantile_1), color="yellow", linetype="dashed", size=1)
</code></pre>

<p><a href="https://i.stack.imgur.com/jCKdo.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jCKdo.png" alt="resulting plot"></a></p>