title: Fixing the order of facets in ggplot
body: <p>Data:</p>
  <pre><code>df &lt;- data.frame(
      type   = c(&quot;T&quot;, &quot;F&quot;, &quot;P&quot;, &quot;T&quot;, &quot;F&quot;, &quot;P&quot;, &quot;T&quot;, &quot;F&quot;, &quot;P&quot;, &quot;T&quot;, &quot;F&quot;, &quot;P&quot;), 
      size   = c(&quot;50%&quot;, &quot;50%&quot;, &quot;50%&quot;, &quot;100%&quot;, &quot;100%&quot;, &quot;100%&quot;, &quot;150%&quot;, &quot;150%&quot;, &quot;150%&quot;, &quot;200%&quot;, &quot;200%&quot;, &quot;200%&quot;),
      amount = c(48.4, 48.1, 46.8, 25.9, 26, 24.9, 21.1, 21.4, 20.1, 20.8, 21.5, 16.5)
  )
  </code></pre>
  <p>I need to plot a bargraph of the above data using ggplot (x-axis -&gt; <code>type</code>, y-axis -&gt; <code>amount</code>, group by <code>size</code>). When I used the following code, I am not getting the variable <code>type</code> and as well as <code>size</code> in the order shown in the data. Please see the figure. I have used the following code for that.</p>
  <pre><code> ggplot(df, aes(type, amount , fill=type, group=type, shape=type, facets=size)) + 
    geom_col(width=0.5, position = position_dodge(width=0.6)) + 
    facet_grid(.~size) + 
    theme_bw() + 
    scale_fill_manual(values = c(&quot;darkblue&quot;,&quot;steelblue1&quot;,&quot;steelblue4&quot;), 
                      labels = c(&quot;T&quot;, &quot;F&quot;, &quot;P&quot;))
  </code></pre>
  <p><img src="https://i.stack.imgur.com/bPkne.png" alt="enter image description here" /> .</p>
  <p>For fixing the order issue, I have used a factor method for the variable &quot;type&quot; using the following. Please see the figure also.</p>
  <pre><code>temp$new = factor(temp$type, levels=c(&quot;T&quot;,&quot;F&quot;,&quot;P&quot;), labels=c(&quot;T&quot;,&quot;F&quot;,&quot;P&quot;)) 
  </code></pre>
  <p><img src="https://i.stack.imgur.com/qNHnv.png" alt="enter image description here" /></p>
  <p>However, now I don't know how to fix the order for the variable <code>size</code>. It should be 50%, 100%. 150%, and 200%.</p>