title: dplyr/ggplot using pipeline
body: <p>Can someone tell me how I integrate the following dplyr code with a ggplot bar chart. I have them both working indipendently but whenever I try to put it together something goes wrong. </p>
  
  <p>Here is the dplyr code which produces a summary table (inserted below script):</p>
  
  <pre><code>pop.2.df %&gt;%
  gather(key = "trial", value = 'capture','sco.1','sco.2', 'sco.3') %&gt;% 
  group_by(trial, capture) %&gt;% summarise(n = n()) 
  
  A tibble: 6 x 3
  Groups:   trial [?] 
  trial capture     n
    &lt;chr&gt;   &lt;chr&gt; &lt;int&gt;
  1 sco.1       n    28
  2 sco.1       y    94
  3 sco.2       n    38
  4 sco.2       y    84
  5 sco.3       n    45
  6 sco.3       y    77
  </code></pre>
  
  <p>Here is the ggplot code which produces the barchart, however I can only get it to work if I first make an object from the script above then plot. I would like to have it all working within one piece of code using pipeline operator:</p>
  
  <pre><code> ggplot(data = pop.2.df.v2) + geom_bar(mapping = aes(x = trial, fill = capture), position = "dodge")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/jvD78.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jvD78.png" alt="plot1"></a></p>