title: Plot variance and confidence interval for variance with ggplot
body: <p>Consider the variables <code>gear</code> and <code>qsec</code> from the standard data set <code>mtcars</code>.</p>
  
  <pre><code>require(ggplot2)
  ggplot(mtcars, aes(x=gear, y=qsec)) + geom_point()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/5veYPm.png" alt="enter image description here"></p>
  
  <p><strong>I am trying to plot the within-group variance (for each group) with error bars.</strong></p>
  
  <p>Here is my current solution (using a 95% confidence interval for error bars):</p>
  
  <pre><code>require(data.table)
  dtmtcars = data.table(mtcars)[,list(var.qsec = var(qsec)),by=list(gear)]
  samplesize = sapply(unique(mtcars$gear), function(x) nrow(subset(mtcars, gear == x)))
  high.EB =  ((samplesize-1)*dtmtcars$var.qsec)/qchisq(0.025,n-1)
  low.EB = ((samplesize-1)*dtmtcars$var.qsec)/qchisq(0.975,n-1)
  ggplot(dtmtcars, aes(x=gear, y=var.qsec)) + geom_point() + geom_errorbar(aes(ymin=low.EB, ymax=high.EB))
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/yo9lp.png" alt="enter image description here"></p>
  
  <p><strong>Is there an easier solution (like an already implemented function in <code>ggplot2</code>)? If not, can you please confirm that my solution was correct?</strong></p>