title: Grouped Bar Chart of Means in R
body: <p>I have a data set (learner) with student test scores (learner$literacy_total), their grade level (ie. grade 1, 2, 3, ..., 12), and their gender (learner$gender). I'd like to create a bar plot that has grade on the x axis, and the average score on the y axis, with two columns for each grade (one for males and one for females) so I can see how boys/girls do in each grade. I can easily create a plot of the overall average for each grade using the following code:</p>
  
  <pre><code>fig.dist &lt;- split(learner$literacy_total, learner$learner_grade)
  fig.mean &lt;- sapply(fig.dist, mean, na.rm = TRUE)
  barplot(fig.mean)
  </code></pre>
  
  <p>But how do I group these so that for each grade I can see the average test scores for boys/girls separately. </p>
  
  <p>In other questions I've seen code that either groups categories or graphs the means, but I'm struggling with how to put the two together.</p>