[R-sig-Geo] Multiple legends with levelplot and spplot
Oscar Perpiñán Lamigueiro
oscar.perpinan at upm.es
Tue Oct 21 07:45:50 CEST 2014
Hello,
You could try to define the legend for the Spatial* object inside the
levelplot call using the `key` argument. For example:
library(sp)
library(raster)
library(rasterVis)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
data(meuse)
coordinates(meuse) = c("x", "y")
meuse$class <- cut(meuse$zinc, 3)
ptsCols <- c('black', 'red', 'blue')
lvp <- levelplot(r, margin = FALSE,
## Define the legend for the spplot graphic
key = list(space = 'top', text = list(levels(meuse$class)),
points = list(pch = 21, fill = ptsCols)),
## Legend for the Raster object
colorkey=list(space="right",width=0.75,height=0.75))
spp <- spplot(meuse["class"], col.regions = ptsCols)
lvp + spp
Best,
Oscar.
--
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica (ETSIDI-UPM)
Grupo de Sistemas Fotovoltaicos (IES-UPM)
URL: http://oscarperpinan.github.io
More information about the R-sig-Geo
mailing list