title: Barplot of summed values per category in R - currently plotting highest value only
body: <p>I have a data set (named <code>data</code>) as follows</p>
  
  <pre><code>  site  year  month  supplier   FG   total  
  540853  2015      1    790122  T25       3  
  540853  2015      3    790122  T25       5  
  540853  2015      3    790122  V24       8  
  540853  2015      4    790122  V24       1  
  540853  2015      4    790122  T25       6  
  540853  2015      4    790122  W29       4  
  540853  2015      5    790122  W29       9  
  540853  2015      5    790122  V24       2  
  540853  2015      5    790122  T25       7 
  </code></pre>
  
  <p>I would like to create a bar plot for all the months ins 2015, suppler 790122, showing the sum of <code>totals</code> for each <code>FG</code>. The x-axis would have T25, W29 and V24. The y-axis would read 23 for T25 (3+5+8+7), 13 for W29 (4+9) and 11 for V24 (8+1+2). </p>
  
  <p>I initially plotted using the following code</p>
  
  <pre><code>plot1 &lt;- ggplot(subset(data, Year %in% c("2015") &amp; supplier %in% c("520302")), 
                  aes(x = factor(FG), y = total)) + 
           geom_bar(stat = "identity", position = "dodge") +
           theme(panel.grid = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"))
  </code></pre>
  
  <p>This produced a barplot that I thought was correct. However, I later wanted to add a table beside it so the readers could see the exact values for each FG, rather than reading it from the graph. Upon doing this I realised that the values in the barplot did not match the values in the table. </p>
  
  <p>I plotted a second graph with the following code</p>
  
  <pre><code>for (i in 790122){
    For_summary &lt;- subset(data, year %in% c("2015") &amp; supplier %in% i)
    summary_tbl &lt;- data.frame(ddply(For_summary, c("FG"), summarise, S = sum(total)))
    colnames(summary_tbl) &lt;- c("FG", "total")
  }
  
  plot2 &lt;- ggplot(summary_tbl, 
                  aes(x = factor(FG), y = total)) + 
    geom_bar(stat = "identity", position = "dodge") +
    ylim(0,25) + labs(title = "plot 2") +
    theme(panel.grid = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"))
  </code></pre>
  
  <p>This gave a barplot with the values I want (see attached image). In the first barplot the R code seems to plot only the highest value for each of the FG.</p>
  
  <p><a href="https://i.stack.imgur.com/RNQGl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RNQGl.jpg" alt="enter image description here"></a></p>
  
  <p>Can anyone advise on what part of the code is doing this and how I can plot it correctly without having the create the <code>summary_tbl</code> in the <code>for</code> loop first?</p>