title: ggplot2 bar plot by two groups and mean of y variable
body: <p>I'm trying to create a bar plot for which I have two groups and the y variable is the mean of one of those groups. </p>
  
  <p><a href="https://i.stack.imgur.com/Swe1U.png" rel="nofollow noreferrer">Sample Bar Graph</a></p>
  
  <p><a href="https://i.stack.imgur.com/Swe1U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Swe1U.png" alt="enter image description here"></a></p>
  
  <p>So looking at the above bar graph in the photo, I have bars grouped by country and prosocial, and on the y-axis I have taken the fraction of prosocial individuals. I am only able, however, to create a bar plot that only takes the mean of prosocial and groups it by country. Basically, it's just one bar per county. Which is not exactly what I'm looking for. So far this is the code I've been using to group the data for the bar plot, which has been somewhat unsuccessful. </p>
  
  <pre><code>plotData &lt;- myData2[!is.na(myData2$prosocial),]
  plotData &lt;- plotData %&gt;% 
    mutate(mean_prosocial = mean(prosocial)) %&gt;% 
    group_by(country) %&gt;%
    summarise(mean_prosocial = mean(prosocial),se = sd(prosocial) / sqrt(n()))
  </code></pre>
  
  <p>This only groups by country and if I want to group by prosocial as well, I obviously just get NAs for the mean variable. Below is a link to the working data: 
  <a href="https://www.dropbox.com/s/8was36h545e18dy/working.example?dl=0" rel="nofollow noreferrer">workable data</a>.</p>
  
  <p>Thanks. </p>