title: Create a rainbow color scale based on a vector, in the order of that vector
body: <p>I'm looking for a more elegant way to do this:</p>
  
  <pre><code>#Create Dataset
  set.seed(1)
  x &lt;- runif(100)
  y &lt;- runif(100)
  z &lt;- y*x
  
  #Assign colors, based on z vector    
  Data &lt;- data.frame(Order=1:length(z),z=z)
  Data &lt;- Data[order(Data$z),]
  Data$col &lt;- rainbow(length(z))
  orderedcolors &lt;- Data[order(Data$Order),'col']
  
  #Plot x vs y, colored by z
  plot(x,y,col=orderedcolors)
  </code></pre>
  
  <p>Basically, I want to assign a color to each point in the <code>z</code> vector, and I want those colors to vary on a rainbow scale from z's lowest values to it's highest values.</p>