title: R: sort barplot colors
body: <p><strong>I have a matrix of data which generate barplot like:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/XwrE4.png" alt="enter image description here"></p>
  
  <p><strong>I want my barblot to be like:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/89xCQ.png" alt="enter image description here"></p>
  
  <p>Where as I note in the comments, the blue segments should always be on the bottom. This is my R code:</p>
  
  <pre><code>file&lt;-read.csv(file="file.csv", sep="\t", header=T)
      m&lt;-table(file)
      m
           path
      mir              cp eip gip mt os
        aga-bantam      0   0   0  4  0
        aga-let-7       0   0   0  2  5
        aga-miR-1       0   0   0  3  0
        aga-miR-10      0  11   9  2  0
        aga-miR-100     4   0   0  0  0
        aga-miR-1000    2   2   0 15  0
        aga-miR-11      5   0   0  0  0
        aga-miR-1174    4   0   0 10  0
        aga-miR-1175    0   0   0  6  0
        aga-miR-12      0   3   0  0  0
        aga-miR-124     0   0   0  8  0
        aga-miR-133     0   5  19  0  0
        aga-miR-137     0   0   2  0  0
        aga-miR-13b     0   0   9  0  0
        aga-miR-184     0   0   0  9  2
        aga-miR-1889    0   0  11  2  0
        aga-miR-1890    0   0   5 11  0
        aga-miR-1891    0   0   0  3  0
        aga-miR-190     0   4   0 13  0
        aga-miR-2       0   0  10  0  0
        aga-miR-210     0   0   0  4  0
        aga-miR-219     0   3   5  0  0
        aga-miR-263     0   2   0  0  7
        aga-miR-263b    0   3   0 16  4
        aga-miR-275     0   4   0  7  2
        aga-miR-276-3p  0   0   4 20  0
        aga-miR-276-5p  2   0   0  4  0
        aga-miR-277     0   0   0 20  0
        aga-miR-278     0   0   0  3  0
        aga-miR-279     0   5   0  0  0
        aga-miR-281     6   5   4  5  0
        aga-miR-282     4   2  15  4  0
        aga-miR-283     0   0   7  1  0
        aga-miR-305     0   3   5 10  0
        aga-miR-307     0   0   0  4  0
        aga-miR-308     0   0   0  0  2
        aga-miR-309     0   0   0  9  0
        aga-miR-315     0   0   0 13  0
        aga-miR-317     0   0   0  4  2
        aga-miR-34      0   3   0  3  0
        aga-miR-375     0   0   0  2  2
        aga-miR-7       0   0   0 10  0
        aga-miR-79      0   0   0  5  0
        aga-miR-8       0   0   3  2  0
        aga-miR-87      5   2   4  0  0
        aga-miR-927     0   0  11  0  0
        aga-miR-929     0   0   0  3  0
        aga-miR-92a     0   0  10  4  0
        aga-miR-92b     0   2   9  0  0
        aga-miR-957     0   0   0  8  0
        aga-miR-965     5   0   0 10  0
        aga-miR-970     0   0   7  5  0
        aga-miR-981     0   4   0  4  0
        aga-miR-989     0   0   0  8  0
        aga-miR-993     0   2   0  3  0
        aga-miR-996     0   0   3  2  0
        aga-miR-9a      0   0   0  3  0
        aga-miR-9b      5   0   0  2  0
        aga-miR-9c      0   0   0  5  0
        aga-miR-iab-4   5   0   0  0  0
  
      barplot (t(m),col=rainbow(5),las=2)
  </code></pre>