ialm
ialm

Reputation: 8717

How to set the maximum and minimum values for a lattice plot?

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)?

Upvotes: 1

Views: 4164

Answers (1)

IRTFM
IRTFM

Reputation: 263391

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

Upvotes: 5

Related Questions