title: How to map error bars in an R geom_violin plot
body: <p>Somewhere I'm making a very simple mistake. Thank you for pointing out where this mistake is happening...</p>
  
  <p>I'd like to create a violin plot with overlaying confidence intervals and a group means. Much like the example at <a href="https://github.com/IndrajeetPatil/ggstatsplot#ggbetweenstats" rel="nofollow noreferrer">this</a> terrific new package. </p>
  
  <p>The generic violin plot without any CI's works fine:</p>
  
  <pre><code>p &lt;- ggplot(data=diamonds, aes(x=cut, y=price))
  p + geom_violin(aes(x=cut, y=price)) +
    geom_jitter(height = 0, width = 0.1, alpha = 0.05) +
    geom_crossbar(stat="summary", fun.y=mean, fun.ymax=mean, fun.ymin=mean, 
                  fatten=2, width=.5)
  </code></pre>
  
  <p>My issues is incorporating the confidence intervals. </p>
  
  <p>I start by creating the necessary summary stats:</p>
  
  <pre><code>errbar_lims &lt;- group_by(diamonds, cut) %&gt;% 
    summarize(mean=mean(price), se=sd(price)/sqrt(n()),             
    upper=mean+(2*se), lower=mean-(2*se))
  </code></pre>
  
  <p>Then I thought to add to the plot with <code>geom_errorbar</code>:</p>
  
  <pre><code>p &lt;- ggplot(data=diamonds, aes(x=cut, y=price))
  p + geom_violin(aes(x=cut, y=price)) +
    geom_jitter(height = 0, width = 0.1, alpha = 0.05) +
    geom_crossbar(stat="summary", fun.y=mean, fun.ymax=mean, fun.ymin=mean, 
                  fatten=2, width=.5) +
    geom_errorbar(aes(x= ymax=errbar_lims$upper, ymin=errbar_lims$lower), 
                  stat='identity', width=.25)
  </code></pre>
  
  <p>But ggplot's error keeps informing me that I'm mapping to a single group aesthetic instead of the 5 groups that I'm trying to plot.</p>
  
  <p>Perhaps my mistake is how I've set the mapping at the very beginning?</p>
  
  <hr>
  
  <p><em>UPDATE</em></p>
  
  <p>After reviewing a few of the comments after posting initially, the full script now looks as follows:</p>
  
  <pre><code>errbar_lims &lt;- group_by(diamonds, cut) %&gt;% 
    summarize(mean=mean(price), se=sd(price)/sqrt(n()), 
          upper=mean+(2*se), lower=mean-(2*se))
  
  p &lt;- ggplot(data=diamonds, aes(x=cut, y=price))
  p + geom_violin(aes(x=cut, y=price)) +    
    geom_jitter(height = 0, width = 0.1, alpha = 0.05) +
    geom_crossbar(stat="summary", fun.y=mean, fun.ymax=mean, fun.ymin=mean, 
              fatten=2, width=.5) +
    geom_errorbar(aes(x = cut, ymin = lower, ymax = upper), errbar_lims, inherit = FALSE)
  </code></pre>
  
  <p>Yet an error persists:</p>
  
  <pre><code>Error in FUN(X[[i]], ...) : object 'price' not found
  </code></pre>