title: Add horizontal lines to stacked barplot in ggplot2 in R, and show in legend
body: <p>I have a stacked barplot, something like the example below.</p>
  
  <p>I want to add one or two sets of horizontal lines (specifying colour and line type) across each bar, at different values for each bar, and add these to the legend. </p>
  
  <pre><code>Titanic.df &lt;- as.data.frame(Titanic)
  
  Titanic.ag &lt;- aggregate( Freq ~ Sex + Class + Age, data=Titanic.df, sum, subset = Survived == "Yes")
  
  bars &lt;- rep(c(0.5, NA, 0.7, NA, 0.6, NA, 0.9, NA), 2)
  
  ggplot(Titanic.ag, aes(x = Class, y = Freq, fill = Sex)) + 
    geom_bar(position = "fill", stat = "identity") + 
    facet_grid(~Age) +
    geom_errorbar(aes(y = bars, ymin = bars, ymax = bars,  col = "Ref1")) + 
    scale_fill_manual(values = c("darkgreen", "darkblue") ) + 
    labs(col = "Reference",
         fill= "",
         y = "Proportion",
         x = "Class")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/WQiGw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/WQiGw.png" alt="titanic stacked bar plot with horizontal lines"></a></p>
  
  <p>I have tried using geom_errorbar() as suggested on several questions, but I am stuck with two things:</p>
  
  <p>If I add a vector of values for the error bars, then ggplot expects the same length as in the dataframe (eg 16 in Titanic.ag), but there are only 8 bars as they are stacked. This is why I have used NAs in <code>bars</code> above.
  Is there an alternative?</p>
  
  <p>More importantly, I want to control colour and line type, but if I add these to geom_bar(), I lose my legend. e.g.</p>
  
  <pre><code>  geom_errorbar(aes(y = bars, ymin=bars, ymax=bars,  col = "Ref1"), col = "red", linetype = 2)
  </code></pre>
  
  <p>Is geom_segment() an alternative? </p>
  
  <p>Edited typos, clarified different values of horziontal lines.</p>