[R] Color intervals in image function (image.plot)

FMH kagba2006 at yahoo.com
Mon Feb 8 18:06:19 CET 2010


Hi,

The script below is my current coding in order to produce a contour plot of temperature across altitude and time. In my case, time,altitude and temperature are represented by x, y and z variables.


##############################################
Brazilan.Pallete <- colorRampPalette(c("blue","green","yellow","red"))
image.plot(x, y, z, col = Brazilan.Pallete(50))
contour(x,y,z, levels = seq(1, 20, by = 1), add = TRUE, col = 'peru')
##############################################



The plot worked fine but i found difficult to fix the interval of the color corresponding to z value. In my case, the range of z values is between 1 and 40 and  i'd like to fix the color in the image correspoding to four sub-intervals of z values. For instance:

1. 1 < z < 10 : blue
2. 11 < z < 20: green
3. 21 < z < 30: yellow
4. 31 < z < 40 : red.

I did't find a suitable coding to do this. Could someone please give an advice on this matter?

Thank you.
Fir







More information about the R-help mailing list