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

Matthew Landis landis at isciences.com
Thu Apr 7 15:00:14 CEST 2011


Edzer - thank you VERY much.  That worked great and solved a problem 
that has been driving me NUTS.

I had never heard of the panel.number() function before. It does not 
seem to be mentioned in the usual places in the help files, or else I 
just missed it.

M

On 4/6/2011 2:47 PM, Edzer Pebesma wrote:
> 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]])
>>         }
>> )

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~
Matthew Landis, Ph.D.
Research Scientist
ISciences, LLC
61 Main St. Suite 200
Burlington VT 05401
802.864.2999
~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the R-sig-Geo mailing list