[R-sig-Geo] spplot with legend only, and legend inside the plotting area

Oscar Perpiñán Lamigueiro oscar.perpinan at upm.es
Thu Mar 8 18:22:58 CET 2012


Mauricio Zambrano-Bigiarini <mauricio.zambrano at jrc.ec.europa.eu> writes:

> Thanks Oscar !. I didn't realise about 'latticeExtra' instead of lattice...
>
> One last question. By using c(), is it possible to put different axis
> labels for each plot ?
> -------------- START ----------------
> library(sp)
> xyz = data.frame(expand.grid(x=1:10,y=1:10),rnorm(100))
> coordinates(xyz)=~x+y
>
> # Different spatial extent for the 2nd dummy set
> xyz2 = data.frame(expand.grid(x=100:200,y=100:200),rnorm(10201))
> coordinates(xyz2)=~x+y
>
> # only to get the default values from 'auto.key'
> dummy <- spplot(xyz, cex=2, alpha=0.7, xlab="X1", ylab="Y1",
> scales=list(draw=TRUE))
> dummy2 <- spplot(xyz2, cex=2, alpha=0.7, xlab="X2", ylab="Y2")
>
> # checking that 'dummy' is a trellis
> class(dummy)
>
> library(lattice)
> library(latticeExtra)
> cObj <- c(dummy, dummy2, dummy, dummy2, layout=c(2,4), merge.legends=FALSE)
> update(cObj)
>
> -------------- END ----------------

Yes, it is possible. You have to modify the parameters with update:

cObj <- c(dummy, dummy2, dummy, dummy2)
update(cObj, xlab=c('X1', 'X2'), ylab.right='Y2')

Best,

Oscar.
-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com



More information about the R-sig-Geo mailing list