[R-sig-Geo] how to pass panel index in spplot
Weidong Gu
wgu at uab.edu
Wed Apr 7 21:20:23 CEST 2010
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 incidents on state map. The reproducible code is below. I thought panel=function () might be the solution but I couldn't get panel index in individual panels.
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(...) {
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
More information about the R-sig-Geo
mailing list