title: Adding legend and changing scale on figure
body: <p>I am trying to add a legend for the mean and median to my histogram. I am also trying to change the scale on the y-axis that is labeled count. It is currently showing the density scale. I want the density plot but the count scale. Alternatively, I would be fine with a second scale or the counts at the end of the histogram. I am just not sure how to go about it. Below is some data and the current code. Thank you in advance.</p>
  <pre><code>studyData=data.frame(X=rchisq(1:100000, df=3))
  colnames(studyData) &lt;- &quot;hoursstudying&quot;
  
  mu &lt;- data.frame(mean(studyData$hoursstudying))
  colnames(mu) &lt;- &quot;Mean&quot;
  med &lt;- data.frame(median(studyData$hoursstudying))
  colnames(med) &lt;- &quot;Median&quot;
  
  p &lt;- ggplot(studyData, aes(x = hoursstudying)) +
    geom_histogram(aes(y=(..density..)), binwidth = 1, colour = &quot;black&quot;, fill = &quot;lightblue&quot;) +
    geom_density(alpha=.2, fill=&quot;#FF6666&quot;) +
    geom_vline(data = mu, aes(xintercept = Mean),
               color = &quot;red&quot;, linetype = &quot;dashed&quot;, size = 1) +
    geom_vline(data = med, aes(xintercept = median(Median)),
               color = &quot;purple&quot;, size = 1) + 
    labs(title = &quot;Hours Spent Completing Course Work&quot;) +
    ylab(&quot;Count&quot;) +
    xlab(&quot;Hours Studying&quot;)
    theme(plot.title = element_text(hjust = 0.5))
  p
  
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/0GdPt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0GdPt.png" alt="enter image description here" /></a></p>