title: Add legend for a custom stat_summary fun.data
body: <p>How can I add a legend for an object I have added to my plot with <code>stat_summary</code>?</p>
  
  <p>Here is an example:</p>
  
  <pre><code>ToothGrowth$dose &lt;- as.factor(ToothGrowth$dose)
  p &lt;- ggplot(ToothGrowth, aes(x=dose, y=len)) + 
      geom_violin(trim=FALSE)
  data_summary &lt;- function(x) {
      m &lt;- mean(x)
      ymin &lt;- m-sd(x)
      ymax &lt;- m+sd(x)
      return(c(y=m,ymin=ymin,ymax=ymax))
  }
  p + stat_summary(fun.data=data_summary)
  
  ### Code from http://www.sthda.com/english/wiki/ggplot2-violin-plot-quick-start-guide-r-software-and-data-visualization
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vC5Du.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vC5Du.png" alt="enter image description here"></a></p>
  
  <p>I want to add a descriptive legend which explains what the line and the dot in the center of each violin plot represents.</p>
  
  <p>According to the RELATED topic below, I am under the impression that this can be achieved by defining <code>aes(shape="")</code> in <code>stat_summary</code> and then adding <code>scale_shape_manual("", values=c("?"))</code>. But I have not had any success.</p>
  
  <p>RELATED. <a href="https://stackoverflow.com/questions/5178813/ggplot2-legend-for-stat-summary">ggplot2 legend for stat_summary</a></p>