title: Sorting a boxplot based on median value
body: <p>I'd like to use R to make a series of boxplots which are sorted by median value. Suppose then I execute:</p>
  
  <pre><code>boxplot(cost ~ type)
  </code></pre>
  
  <p>This would give me some boxplots were cost is shown on the y axis and the type category is visible on the x-axis:</p>
  
  <pre><code>-----     -----
    |         |
   [ ]        |
    |        [ ]
    |         |
  -----     -----
    A         B
  </code></pre>
  
  <p>However, what I'd like is the boxplot figures sorted from highest to lowest median value. My suspicion is that what I need to do is change the labels of the type (A or B) to numerically indicate which is the lowest and highest median value, but I wonder if there is a more clever way to solve the problem.</p>