1
votes

I am making plots of rasters using the rasterVis package, which uses lattice to generate plots. I am making level plots for some data, and the plot automatically chooses the colour scheme based on the values of the input data set.

For example, say my data is in the form of (x,y,z), where x is the horizontal position of a data point, y is the vertical position, and z represents the elevation. If I create a levelplot with my data, the colour of the data depends on z. By default, lattice uses the range of z to choose the colour scheme of my plot. However, to make my plot comparable to other data sets, I want to manually set the limits of the colours.

Another example: here is a picture from the rasterVis website: rasterVis image

By default, the darkest red is the lowest z value in the data, and the darkest blue is the highest z value in the data. Is there a way to manually set the limits of the colour scheme to something else, say for example, c(-3000, 3000)?

1
Showing a picture from an unattributed external site but with no code or data doesn't really fit with the premise of SO. Code ... we need code. - IRTFM
try the at parameter of levelplot - baptiste
@DWin Sorry, I tried to describe my question the best I could without posting my code, and 'stole' a picture to help describe the problem. In hindsight, I should have taken more effort in making my question. Thanks for your answer. - ialm
It would have been sufficient in this case to just post a link to the page where you got the image. (It had all the data and code needed.) - IRTFM

1 Answers

5
votes

The code to produce tha above image is at: http://rastervis.r-forge.r-project.org/

One does need to first download two different large zip files and alter the code for setting the working directory.

One way of answering this is to subset the values you do want plotted.

levelplot(Aug-meanAug, par.settings=RdBuTheme, 
                       subset= Aug > -1500 & Aug < 500 )

enter image description here

To produce an expanded range you need to match the plotting specs to the colorkey

rgb.palette <- colorRampPalette(c("red", "orange", "blue"),
                             space = "rgb")

levelplot(Aug-meanAug, col.regions=rgb.palette(16), 
                     at=seq(-3000, 3000, length=15) , contour=TRUE, 
                      colorkey=list( at=seq(-3000, 3000, length=15), 
                                      col=rgb.palette(16) ))

enter image description here