title: How do I generate a mapping from numbers to colors in R?
body: <p>In R, I can easily generate a color ramp, for example colorRampPalette. The following produces a sequence of five colors, from blue to red:</p>
  
  <pre><code>&gt; mypal &lt;- colorRampPalette( c( "blue", "red" ) )( 5 )
  &gt; mypal
  [1] "#0000FF" "#3F00BF" "#7F007F" "#BF003F" "#FF0000"
  </code></pre>
  
  <p>How can I easily map a vector of numbers on this palette? Say, I have a vector of numbers between 0 and 10, like this:</p>
  
  <pre><code>x &lt;- c( 1, 9, 8.5, 3, 3.4, 6.2 )
  </code></pre>
  
  <p>I would like a function, say <code>map2color</code>, such that when I run <code>map2color( mypal, x )</code>, I get</p>
  
  <pre><code>#0000FF, #FF0000, #FF0000, #3F00BF, #3F00BF, #BF003F
  </code></pre>
  
  <p>I usually do something like the following</p>
  
  <pre><code>mypalette[ findInterval( x, seq( 0, 10, length.out= 6 ), rightmost.closed= T ) ]
  </code></pre>
  
  <p>but maybe there is a better solution OOB, automatically generating a color scale for a numeric vector.</p>