title: GGplot2: bar plot of means
body: <p><strong>Note:</strong> This question is a duplicate, but there's an additional solution below that wasn't given in the original question, and might be more useful in some cases. </p>
  
  <p>I am trying to create a series of bar charts from data which have a number of repeats for each category - here is a small reproducible example. What I want is the bar chart to show the average of <code>conc</code>s for each <code>bleach_time</code>. When plotting the bar chart straight from <code>df</code> the sum of all <code>conc</code>s is shown on the bar chart.</p>
  
  <pre><code>library(ggplot2)
  
  bleach_time &lt;- c(0, 0, 0, 0, 0, 0, 24, 24, 24, 24, 24, 24)
  conc &lt;- c(23, 54, 12, 96, 34, 65, 34, 22, 35, 06, 90, 69)
  df &lt;- data_frame(bleach_time, conc)
  
  df_p &lt;- ggplot(df, aes(as.factor(bleach_time), conc))
  
  df_p + geom_bar(stat = "identity", na.rm = TRUE)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/XRLkV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XRLkV.png" alt="Bar chart with sum of all data"></a></p>
  
  <p>I can create a summary data frame of the averages for each <code>bleach time</code> then replot the bar chart with <code>df_av</code>, but I would prefer not to have to add in this additional step and data frame as the data frames I'm working with are very large and I have a lot of plots to draw. Is there a way I can choose the average of <code>conc</code>s in the call to plot?</p>
  
  <pre><code>library(dplyr)
  df_av &lt;- df %&gt;% group_by(bleach_time) %&gt;% summarise_all(mean)
  </code></pre>