title: Is there a way to use vectors to determine the order of x-axis labels and plot colours when using facet_wrap in ggplot2?
body: <p>I would like to make 3 plots using facet_wrap, where I could set the order of the x-axis based on <code>myOrder</code>, and the colours based on <code>myColours</code>.
  I have the following <code>data.frame</code>:</p>
  
  <pre><code>Cell &lt;- c("AAA", "AAA", "AAA", "AAA", "AAA", "AAA", "AAA", "AAA", "AAA", 
        "AAA", "ABB", "ABB", "ABB", "ABB", "ABB", "ABB", "ABB", "ABB", 
        "ABB", "ABB", "ACB", "ACB", "ACB", "ACB", "ACB", "ACB", "ACB", 
        "ACB", "ACB", "ACB", "BAA", "BAA", "BAA", "BAA", "BAA", "BAA", 
        "BAA", "BAA", "BAA", "BAA", "BCA", "BCA", "BCA", "BCA", "BCA", 
        "BCA", "BCA", "BCA", "BCA", "BCA", "BCC", "BCC", "BCC", "BCC", 
        "BCC", "BCC", "BCC", "BCC", "BCC", "BCC", "CAA", "CAA", "CAA", 
        "CAA", "CAA", "CAA", "CAA", "CAA", "CAA", "CAA", "CCC", "CCC", 
        "CCC", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC", "CBA", 
        "CBA", "CBA", "CBA", "CBA", "CBA", "CBA", "CBA", "CBA", "CBA")
  Mean &lt;- c(8, 11, 37, 3, 30, 8, 38, 50, 9, 31, 27, 41, 16, 
        29, 4, 29, 28, 22, 48, 36, 13, 46, 21, 41, 38, 21, 
        26, 27, 49, 4, 38, 44, 49, 48, 32, 3, 6, 25, 33, 
        9, 9, 6, 8, 43, 21, 44, 41, 49, 32, 35, 40, 2, 41, 
        34, 22, 12, 0, 21, 39, 30, 49, 26, 26, 39, 4, 13, 
        18, 12, 9, 29, 24, 40, 38, 17, 40, 13, 30, 8, 9, 
        11, 40, 19, 46, 6, 49, 38, 16, 1, 34, 22)
  Type &lt;- c("1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", 
        "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", 
        "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", 
        "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", 
        "2", "2", "2", "2", "2", "2", "2", "2", "2", "3", "3", "3", "3", 
        "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", 
        "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3")
  TesT &lt;- data.frame(Cell,Mean, Type)
  </code></pre>
  
  <p>I have been trying to plot these data using ggplot with the following code:</p>
  
  <pre><code>myOrder &lt;- c("AAA", "ACB", "ABB", "BCA", "BAA", "BCC", "CBA", "CAA", "CCC")
  myColours &lt;- c("red", "blue", "green", "red", "blue", "green", rep("grey", 3))
  
  ggplot(TesT, aes(x = Cell, y = Mean, fill = Cell)) + 
    theme_bw() +
    stat_boxplot(geom = "errorbar") +
    geom_boxplot(colour = "black") +
    scale_x_discrete(breaks = myOrder, labels = myOrder) +
    scale_fill_manual(limits = myOrder, values = myColours) + 
    facet_wrap(~Type, scales = "free_x") +
    scale_shape()
  </code></pre>
  
  <p>This is what I get:</p>
  
  <p><a href="https://i.stack.imgur.com/cKtgR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cKtgR.png" alt="enter image description here"></a></p>
  
  <p>My problem is that I do not manage to get the x-axis in the correct order (the order in <code>myOrder</code>).
  The only way in which I managed to do this was by changing <strong>breaks</strong> to <strong>limits</strong>  (<code>scale_x_discrete(limits = myOrder, labels = myOrder)</code>). However, when I do this I get all the possible x categories in all the plots:
   <a href="https://i.stack.imgur.com/9LLaC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9LLaC.png" alt="enter image description here"></a></p>
  
  <p>I have spent quite some time looking for an answer in here and in google but nothing seems to solve my problem. Does anyone have a suggestion?</p>