Greetings and Happy Holidays!

I am an ~experienced R user but new to spatially oriented packages.  I  
have been trying to add a 'background' shape to a ssplot.  My example  
is to add a background state map to the sids data.

My 2 questions, 1) What am I missing with the spplot - lattice  
interaction[this seems like it should be simple]?, and 2) is there a  
better way to add the 'background' map if the object is a  
SpatialPolygonsDataFrame?

#Examples mostly from http://r-spatial.sourceforge.net/gallery/
#Library's required for example
library(sp)
library(grid)
library(lattice)
library(maps)
library(RColorBrewer)
library(maptools)

#First a Basic plot and an added map

nc1 <- readShapePoly(system.file("shapes/sids.shp", package="maptools") 
[1], proj4string=CRS("+proj=longlat +datum=NAD27"))

names(nc1)
rrt <- nc1$SID74/nc1$BIR74
brks <- quantile(rrt, seq(0,1,1/7))
cols <- grey((length(brks):2)/length(brks))
dens <- (2:length(brks))*3
plot(nc1, col=cols[findInterval(rrt, brks, all.inside=TRUE)])

# add US State map
map('state', add=TRUE, xlim=par('usr')[1:2], ylim=par('usr')[3:4])


#This works fine, but I have issues when using spplot.

example
nc1$f = factor(sample(1:5,100,replace=T),labels=letters[1:5])
nc1$g = factor(sample(1:5,100,replace=T),labels=letters[6:10])

spplot(nc1, c("f","g"), col.regions=brewer.pal(10, "Set3"),  
scales=list(draw = TRUE))


# create a custom panel to add a map polygon to lattice plot

panel.mapper <- function(...){
		library(maps)
		mp<-map('state', fill=TRUE, plot=FALSE)	
	  	lpolygon(mp$x, mp$y, col='gray', ...)
	}

#The panel mapper appears to work
spplot(nc1, c("f","g"), col.regions=brewer.pal(10, "Set3"),  
scales=list(draw = TRUE), panel=function(...) {
	panel.mapper()
	})	

#However I can seem to pass the polygon colors argument through ssplot
spplot(nc1, c("f","g"), col.regions=brewer.pal(10, "Set3"),  
scales=list(draw = TRUE),
	panel=function(...) {
		panel.mapper()
		sp.polygons(nc1)
		}
	)	


Thanks for the help and happiest holidays.

Jon Loehrke
Graduate Research Assistant
Department of Fisheries Oceanography
School for Marine Science and Technology
University of Massachusetts
200 Mill Road, Suite 325
Fairhaven, MA 02719
jloehrke@umassd.edu
 > sessionInfo()
R version 2.8.1 (2008-12-22)
i386-apple-darwin8.11.1

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets   
methods   base

other attached packages:
[1] lattice_0.17-17    RColorBrewer_1.0-2 maps_2.0-40         
maptools_0.7-15    foreign_0.8-29     sp_0.9-28

loaded via a namespace (and not attached):
[1] tools_2.8.1


	[[alternative HTML version deleted]]


