-----Original Message-----
From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de]
Sent: Wednesday, April 07, 2010 4:01 PM
To: Weidong Gu
Cc: 'r-sig-geo at stat.math.ethz.ch'
Subject: Re: [R-sig-Geo] how to pass panel index in spplot
Weidong, is
library(maps)
library(maptools)
state=map('state',plot=F,fill=T)
IDs=sapply(strsplit(state$names,':'), function(x) x[1])
crs=CRS('+proj=longlat +ellps=WGS84')
sp.st=map2SpatialPolygons(state, IDs, proj4string=crs)
state.inc=data.frame(State=sapply(slot(sp.st,'polygons'),function(x)
slot(x,'ID')))
state.inc$D1=rpois(length(state.inc$State),100)
state.inc$D2=rpois(length(state.inc$State),150)
row.names(state.inc)=state.inc$State
inc.spdf=SpatialPolygonsDataFrame(sp.st,state.inc)
spplot(inc.spdf, zcol=2:3,
panel = function(x,y,z,subscripts,...) {
panel.polygonsplot(x,y,z,subscripts,...)
sp.text(coordinates(inc.spdf), z[subscripts])
}
)
what you want?
Weidong Gu wrote:
Thanks Edzer for advising the option. But I could not figure out how
to draw spatial polygons like state map with xyplot.
-----Original Message-----
From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de]
Sent: Wednesday, April 07, 2010 3:09 PM
To: Weidong Gu
Cc: 'r-sig-geo at stat.math.ethz.ch'
Subject: Re: [R-sig-Geo] how to pass panel index in spplot
Dear Weidong,
for multi-group panel functions, the way to retrieve subscripts in
custom panel functions is
panel = function(x,y,subscripts, ...) {
... # do sth with subscripts here
}
see also
library(lattice)
?panel.superpose
I hope this helped,
Weidong Gu wrote:
Hi,
I have a question about spplot: can it transfer somehow panel index,
such as subscripts in xyplot to panels.
The question arose when I needed to plot numbers of disease
on state map. The reproducible code is below. I thought
() might be the solution but I couldn't get panel index in
library(maps)
library(maptools)
state=map('state',plot=F,fill=T)
IDs=sapply(strsplit(state$names,':'), function(x) x[1])
crs=CRS('+proj=longlat +ellps=WGS84')
sp.st=map2SpatialPolygons(state, IDs, proj4string=crs)
state.inc=data.frame(State=sapply(slot(sp.st,'polygons'),function(x)
state.inc$D1=rpois(length(state.inc$State),100)
state.inc$D2=rpois(length(state.inc$State),150)
row.names(state.inc)=state.inc$State
inc.spdf=SpatialPolygonsDataFrame(sp.st,state.inc)
spplot(inc.spdf, zcol=2:3,
panel = function(...) {
sp.polygons(inc.spdf)
sp.text(coordinates(inc.spdf),zcol)
}
)
I would appreciate you help and advice.
Weidong Gu
University of Alabama, Birmingham
220A Bevill Biomedical Research Bldg
845 19th Street S., Birmingham, Alabama 35294