title: In R, how to create contour plot where lines indicate elevation and color indicate magnitude of a separate value?
body: <p>My specific example: I have a dataframe, say 'df', containing columns of x coordinates, y coordinates, elevation, and I have a vector of precipitation values associated with the x/y coordinates (say the variable name is 'prec').</p>
  
  <p>I can create a 3d representation with:</p>
  
  <pre><code>myColorRamp &lt;- function(colors, values) {
  v &lt;- (values - min(values))/diff(range(values))
  x &lt;- colorRamp(colors)(v)
  rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
  }
  library(rgl)
  cols &lt;- myColorRamp(c("red", "white", "blue"), prec)
  plot3d(df$xcoord, df$ycoord, df$Elev, type="p", size=3, xlab='x', ylab='y', zlab='elevation', col = cols)
  </code></pre>
  
  <p>I'm looking to basically have a 2d representation of the same picture, where instead of a 3d plot, the 3rd dimension of elevation is represented using contour lines.</p>
  
  <p>ie: I want a contour plot like so:
  <a href="http://mathworld.wolfram.com/images/eps-gif/ContourPlot_1000.gif" rel="nofollow noreferrer">http://mathworld.wolfram.com/images/eps-gif/ContourPlot_1000.gif</a>
  but instead of the colors indicating magnitude of the elevation, I want it to indicate the levels of precipitation.</p>
  
  <p>I've looked at <a href="https://stats.stackexchange.com/questions/31726/scatterplot-with-contour-heat-overlay">https://stats.stackexchange.com/questions/31726/scatterplot-with-contour-heat-overlay</a> and <a href="https://stackoverflow.com/questions/7714677/r-scatterplot-with-too-many-points">R: Scatterplot with too many points</a> but they don't seem to apply to this particular problem and I'm struggling with the example given in <a href="http://stat.ethz.ch/R-manual/R-patched/library/graphics/html/filled.contour.html" rel="nofollow noreferrer">http://stat.ethz.ch/R-manual/R-patched/library/graphics/html/filled.contour.html</a> because my z value is a vector, not a matrix.</p>
  
  <p>Any help is appreciated.</p>