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').
I can create a 3d representation with:
myColorRamp <- function(colors, values) {
v <- (values - min(values))/diff(range(values))
x <- colorRamp(colors)(v)
rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}
library(rgl)
cols <- 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)
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.
ie: I want a contour plot like so: http://mathworld.wolfram.com/images/eps-gif/ContourPlot_1000.gif but instead of the colors indicating magnitude of the elevation, I want it to indicate the levels of precipitation.
I've looked at https://stats.stackexchange.com/questions/31726/scatterplot-with-contour-heat-overlay and R: Scatterplot with too many points but they don't seem to apply to this particular problem and I'm struggling with the example given in http://stat.ethz.ch/R-manual/R-patched/library/graphics/html/filled.contour.html because my z value is a vector, not a matrix.
Any help is appreciated.