I have to plot some plot(x,y) scatters, but i would like the points to be color coded based on the value of a continuous variable z.
I would like a temperature palette (from dark blue to bright red). I tried with Rcolorbrewer however the the RdBu palette (which resembles the temperature palette) uses white for the middle values which looks very bad.
I would also like to plot a legend explaining the color coding with a sample of colors and corresponding values.
Any ideas if this can be performed easily in R? No ggplot please!
Season greetings to everybody
Building off of @BenBolker’s answer, you can do the legend if you take a peek at the code for
filled.contour. I hacked that function apart to look like this:And then applying the code from Ben’s example we get this:
which produces a plot like this:
Fair warning, I really did just hack apart the code for
filled.contour. You will likely want to inspect the remaining code and remove unused bits, or fix parts that I rendered non-functional.