title: How to reorder boxplot labels in ggplot2
body: <ol>
  <li><p>I want to plot first figure with no NAs and order by median. I think I could do this by using na.omit and the code1 below. </p></li>
  <li><p>How can plot the second figure by keeping the ones that are in figure1 (carA and carC) and also keep the same ordering as in figure 1.</p></li>
  </ol>
  
  <p>a</p>
  
  <pre><code>      R   G    T
  EG1   2  20 carA
  EG2   4  40 carA
  EG3   8  80 carA
  EG4  10 100 carA
  EG5  NA  20 carB
  EG6  NA  40 carB
  EG7  NA  50 carB
  EG8  NA  90 carB
  EG9   4  50 carC
  EG10  8  60 carC
  EG11 12  70 carC
  EG12 24  90 carC
  </code></pre>
  
  <p>code1</p>
  
  <pre><code>ggplot(a, aes(reorder(T, log2(R+1), median, order=TRUE), log2(R+1), fill=T)) + geom_boxplot()+coord_flip()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/uvFDs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uvFDs.png" alt="enter image description here"></a></p>
  
  <p>code2</p>
  
  <pre><code>ggplot(a, aes(reorder(T, log2(G+1), median, order=TRUE), log2(G+1), fill=T)) + geom_boxplot()+coord_flip()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/D1vhR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D1vhR.png" alt="enter image description here"></a></p>