title: Changing the order of the groups in ggplot in R
body: <p>I am using <code>ggplot</code> to draw a bar chart. How can I change the order of the groups in the bars? In the following example, I want to have type=1984 as the first stack of the bars, then type=1985 on top of 1984 and so on.</p>
  
  <pre><code>  series &lt;- data.frame(
    time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)),
    type = c(1984:1987),
    value = rpois(16, 10)
  )
  
  ggplot(series, aes(time, value, group = type)) +
    geom_col(aes(fill= type))
  </code></pre>
  
  <p>Changing the order using <code>series&lt;- series[order(series$type, decreasing=T),]</code> only changes the order in the legend not in the plot.</p>
  
  <p><a href="https://i.stack.imgur.com/G0M9S.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G0M9S.jpg" alt=""></a></p>