title: R use list of values as color scale
body: <p>I'd like to represent the value of a variable as a color of a dot in a scatter in R.</p>
  
  <pre><code>x &lt;- rnorm(100) + 5
  y &lt;- rnorm(100) + 5
  plot(x, y)
  </code></pre>
  
  <p>Here, I'd like to use a variable as input for the coloring. But if I try </p>
  
  <pre><code>plot(x, y, col = x)
  </code></pre>
  
  <p>I get something weird, probably obviously. Now I can get what I want like this:</p>
  
  <pre><code>x_norm = (x - min(x)) / (max(x) - min(x))
  col_fun &lt;- colorRamp(c("blue", "red"))
  rgb_cols &lt;- col_fun(x_norm)
  cols &lt;- rgb(rgb_cols, maxColorValue = 256)
  plot(x, y, col = cols)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/oGHy7.png" alt="enter image description here"></p>
  
  <p>But that seems a little elaborate, and to get it working with NA or NaN values, for example by giving them black as color, is not so easy. For me. Is there an easy way to do this that I'm overlooking? </p>