This question should be easy! I am using spplot for visualizing a map with suitable results. However, I would like to know how to set the limits of z, because the values are not being discriminated.

My data frame (df) is: long, lat, Z

spplot(df, "Z") 


  • 1
    what does range(df$Z) say? Because it looks like you've got something in the region of 10^57 in there. Some kind of missing value code? – Spacedman Apr 28 '16 at 20:18

Spacedman ist probably right but you could subset your dataframe before plotting like:

df <- df[df$Z < 300,]
spplot(df, "Z")

This looks indeed like some sort of missing value (as suggested by @Spacedman). Anyway, as a straightforward alternative to subsetting your data (as suggested by @nebi), you could simply use the zcol argument inside spplot to display only a desired range of values. Here is a reproducible example.

rst <- raster(volcano)

## no 'zlim' specified
p1 <- spplot(rst)
## 'zlim' specified
p2 <- spplot(rst, zlim = c(100, 175))

grid.arrange(p1, p2, ncol = 2)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.