I am trying to overlap four raster layers using level plot, I seem to have it all good but the raster just does not show up in the graph, any hint?
require(raster)
library(rasterVis)
r <- raster(nrows=10, ncols=10)
p = CRS("+proj=longlat +datum=WGS84")
r <- setValues(r, 1:ncell(r))
projection(r)=p
r2 <- setValues(r, 1:ncell(r)*2)
projection(r2)=p
r3 <- setValues(r, 1:ncell(r)*3)
projection(r3)=p
r4 <- setValues(r, 1:ncell(r)*4)
projection(r4)=p
plotOptions <- list(panel.aspect = 1, layout = c(1, 1))
levelplot(r, margin = FALSE, par.settings = rasterTheme,
main = "Overplotting Four r Layers",
interpolate = FALSE,
at = seq(0, 1, length = 100),
panel = function(x, y, z, ...) {
# Overplot the other three r layers
plot(r2, add = TRUE, col.regions = "red")
plot(r3, add = TRUE, col.regions = "green")
plot(r4, add = TRUE, col.regions = "blue")
# Set the axis limits to match the first r layer
xlim(extent(r)[1:2])
ylim(extent(r)[3:4])
},
par.strip.text = list(cex = 1.2),
scales = list(draw = TRUE),
colorkey = FALSE,
... = plotOptions)
Thanks in advance,