title: Color according to value in stack barplot R
body: <p>I am building a stacked bar plot using the following code</p>
  
  <pre><code>test &lt;- as.matrix(read.csv(file="test4.csv",sep=",",head=TRUE))
  test &lt;- test[,2:ncol(test)]
  pdf(file="test.pdf", height=15, width=20)
  par(lwd = 0.3)
  xLabLocs &lt;- barplot(test, space=0.4, xaxt='n', yaxt='n', col=heat.colors(13))
  axis(1, cex.axis=0.5, las=2, at=xLabLocs, labels=colnames(test))
  axis(2, cex.axis=0.5, pos=-0.5)
  dev.off()
  </code></pre>
  
  <p>And I would like the colors of each section to be proportional to its height. For example, if each stack is made up of X number of sections, the section with the longest height would be at one end of the "spectrum"(ie really bright blue), and the shortest height section would be at the other end of the "spectrum"(ie really dim blue).</p>
  
  <p>This is what I get instead:
  <img src="https://i.stack.imgur.com/1uHae.png" alt="enter image description here"></p>
  
  <p>In this case what I get is sections at the bottom at one end of the spectrum and the sections at the top at the other end of the spectrum. 
  Thanks</p>
  
  <p>This is some sample data</p>
  
  <pre><code>BARCODES,   BC1_AATCAGGC,   BC10_ACAAGGCT,  BC11_ACACGATC,  BC12_ACACTGAC
  1,  2432,   420,    18, 69
  2,  276,    405,    56, 86
  3,  119,    189,    110,    51
  4,  90, 163,    140,    68
  5,  206,    280,    200,    122
  6,  1389,   1080,   1075,   614
  7,  3983,   3258,   4878,   2994
  8,  7123,   15828,  28111,  7892
  9,  8608,   48721,  52576,  21220
  10, 9639,   44725,  55951,  18284
  11, 8323,   45695,  32166,  7747
  12, 2496,   18254,  26600,  5134
  13, 1524,   8591,   18583,  3705
  </code></pre>