title: control the order of bars in a barchart using R ggplot
body: <p>Using R, I want bars in a bar chart in a certain order.</p>
  <p>The order is:</p>
  <pre><code>a&lt;-c(&quot;no exercise&quot;, &quot;strength&quot;, &quot;moderate aerobics&quot;, &quot;moderate aerobics + strength&quot;, &quot;high aerobics&quot;)
  
  </code></pre>
  <p>And then the values, let's just say:</p>
  <pre><code>b&lt;- c(10, 20, 25, 40, 40)
  df&lt;-data.frame(a, b)
  </code></pre>
  <p>When creating a bar plot, the order of bars is alphabetic, rather than the original:</p>
  <pre><code>ggplot(df) +
    geom_bar( aes(x=a, y=b), stat=&quot;identity&quot;, fill=&quot;red&quot;)
  </code></pre>
  <p>[enter image description here][1]
  Is there a way to change that?</p>
  <p>[1]: <a href="https://i.stack.imgur.com/sZDXc.png##" rel="nofollow noreferrer">https://i.stack.imgur.com/sZDXc.png##</a> Heading ##</p>