title: Problems with stat_summary by group
body: <p>My ultimate aim here is to have <code>stat_summary</code> add summary lines to a plot, using existing group memberships. I'm having trouble getting the lines to plot, and while I understand the problem, I can't figure out how to avoid causing it.</p>
  
  <p>An example:</p>
  
  <pre><code>library(ggplot2)
  df &lt;- data.frame(low=c(20,24,18,16), 
                   mid=c(60,61,48,45), 
                   high=c(80,75,81,83), 
                   category=factor(seq(1:4)), 
                   membership=factor(c(1,1,2,2)))
  
  p &lt;- ggplot(df, aes(x=category, y=mid)) +
    geom_linerange(aes(ymin=low, ymax=high)) +
    geom_point(shape=95, size=8)
  p
  </code></pre>
  
  <p>This produces a plot of each of the four categories:
  <a href="https://i.stack.imgur.com/RoV2x.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RoV2x.jpg" alt="enter image description here"></a></p>
  
  <p>First step is to use <code>stat_summary</code> to add a line showing the means of <code>ymin</code>, <code>y</code> and <code>ymax</code>, like so:</p>
  
  <pre><code>p + 
    stat_summary(data=df, aes(x="Aggregate", ymin=mean(low), y=mean(mid), ymax=mean(high)), 
                 fun.data="mean", geom="linerange", inherit.aes=F) +
    stat_summary(data=df, aes(x="Aggregate", y=mid), fun.y="mean", geom="point", 
                 size=8, shape=95)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/F7VOd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F7VOd.jpg" alt="enter image description here"></a></p>
  
  <p>But when I try to use the memberships in <code>df</code> to produce means within groups, I run into problems with <code>linerange</code> (though <code>point</code> plots fine).</p>
  
  <pre><code>p + 
    stat_summary(data=df, aes(x="Aggregates", ymin=low, y=mid, ymax=high, group=membership), 
                 fun.ymin="mean", fun.y="mean", fun.ymax="mean", geom="linerange", 
                 inherit.aes=F, position_dodge(0.5))
    stat_summary(data=df, aes(x="Aggregates", y=mid, group=membership), 
                 fun.y="mean", geom="point", size=8, shape=95, position_dodge(0.5))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/BTf1v.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BTf1v.jpg" alt="enter image description here"></a></p>
  
  <p>I know from <code>ggplot_build(p)</code> that <code>ymin</code>=<code>y</code>=<code>ymax</code>, which is why nothing is showing on the plot. However, if I use <code>fun.data</code> rather than <code>fun.ymin</code>/<code>fun.ymax</code> I get errors about not having required <code>ymin</code> and <code>ymax</code> aesthetics.</p>
  
  <pre><code>$data[[3]]
        x group ymin    y ymax 
  1 5.125     2 46.5 46.5 46.5 
  2 4.875     1 60.5 60.5 60.5 
  </code></pre>
  
  <p>Any help would be appreciated!</p>