title: Reverse stacked bar order
body: <p>I'm creating a stacked bar chart using ggplot like this:</p>
  
  <pre><code>plot_df &lt;- df[!is.na(df$levels), ] 
  ggplot(plot_df, aes(group)) + geom_bar(aes(fill = levels), position = "fill")
  </code></pre>
  
  <p>Which gives me something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/cNeVb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cNeVb.png" alt="enter image description here"></a></p>
  
  <p>How do I reverse the order the stacked bars themselves, so that level 1 is at the bottom, and level 5 is at the top of each bar?</p>
  
  <p>I've seen a number of questions on this (e.g. <a href="https://stackoverflow.com/questions/32345923/how-to-control-ordering-of-stacked-bar-chart-using-identity-on-ggplot2">How to control ordering of stacked bar chart using identity on ggplot2</a>) and the common solution seems to be to reorder the dataframe by that level as that what ggplot is using the determine the order</p>
  
  <p>So I've tried reordering using dplyr:</p>
  
  <p><code>plot_df &lt;- df[!is.na(df$levels), ] %&gt;% arrange(desc(levels))</code></p>
  
  <p>However, the plot comes out the same. It also doesn't seem to make a difference whether I arrange by ascending or descending order</p>
  
  <p>Here is a reproducible example:</p>
  
  <pre><code>group &lt;- c(1,2,3,4, 1,2,3,4, 1,2,3,4, 1,2,3,4, 1,2,3,4, 1,2,3,4)
  levels &lt;- c("1","1","1","1","2","2","2","2","3","3","3","3","4","4","4","4","5","5","5","5","1","1","1","1")
  plot_df &lt;- data.frame(group, levels)
  
  ggplot(plot_df, aes(group)) + geom_bar(aes(fill = levels), position = "fill")
  </code></pre>