[R-sig-Geo] varying polygon layer with panel in spplot

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed Apr 6 20:47:27 CEST 2011


Matthew, please try this:

spplot(sgdf, c('cd','cu', 'pb', 'zn'),
       names.attr = c('Cadmium', 'Copper', 'Lead', 'Zinc'),
       as.table = TRUE, main = "Testing",
       panel = function(x, y, z, subscripts, ...){
           panel.gridplot(x, y, z, subscripts, ...)
           sp.points(pts.list[[panel.number()]])
       }
)

subscripts refers to the grid cell numbers, after they're all stacked to
a long table; they do not match your pts.list entries.

On 04/06/2011 05:45 PM, Matthew Landis wrote:
> 
> library(sp)
> library(lattice) # required for trellis.par.set():
> trellis.par.set(sp.theme()) # sets color ramp to bpy.colors()
> 
> data(meuse)
> coordinates(meuse)=~x+y
> 
> library(gstat, pos = match(paste("package", "sp", sep=":"), search()) + 1)
> data(meuse.grid)
> coordinates(meuse.grid) = ~x+y
> gridded(meuse.grid) = TRUE
> 
> v.cd = variogram(log(cadmium) ~ 1, meuse)
> ok.model.cd = fit.variogram(v.cd, vgm(1, 'Exp', 500, 1))
> cd.ok <- krige(log(cadmium) ~ 1, meuse, meuse.grid, model = ok.model.cd)
> 
> v.cu <- variogram(log(copper) ~ 1, meuse)
> ok.model.cu <- fit.variogram(v.cu, vgm(1, 'Exp', 500, 1))
> cu.ok <- krige(log(copper) ~ 1, meuse, meuse.grid, model = ok.model.cu)
> 
> v.pb <- variogram(log(lead) ~ 1, meuse)
> ok.model.pb <- fit.variogram(v.pb, vgm(1, 'Exp', 500, 1))
> pb.ok <- krige(log(lead) ~ 1, meuse, meuse.grid, model = ok.model.pb)
> 
> v.zn = variogram(log(zinc)~1, meuse)
> ok.model.zn = fit.variogram(v.zn, vgm(1, "Exp", 500, 1))
> zn.ok = krige(log(zinc)~1, meuse, meuse.grid, model = ok.model.zn)
> 
> sgdf = cd.ok
> 
> sgdf[['cd']] <- cd.ok[['var1.pred']]
> sgdf[['cu']] <- cu.ok[['var1.pred']]
> sgdf[['pb']] <- pb.ok[['var1.pred']]
> sgdf[['zn']] <- zn.ok[['var1.pred']]
> 
> pts.list <- list(meuse[, 'cadmium'], meuse[, 'copper'], meuse[, 'lead'],
> meuse[, 'zinc'])
> 
> spplot(sgdf, c('cd','cu', 'pb', 'zn'),
>        names.attr = c('Cadmium', 'Copper', 'Lead', 'Zinc'),
>        as.table = TRUE, main = "Testing",
>        panel = function(x, y, z, subscripts, ...){
>            panel.gridplot(x, y, z, subscripts, ...)
>            sp.points(pts.list[[subscripts]])
>        }
> )

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list