spplot() maps
The spplot() function in the sp() package is a Lattice-plot type method, and can be thought of as either extending the capabilities of Lattice plots to maps, or extending the ability of R to produce multi-panel maps.
The following example uses a data set of locations and elevations Oregon cirque basins (upland basins eroded by glaciers), and whether or not they are currently (early 21st century) glaciated. Here are the links to the shapefile components: [.dbf] [.shp] [.shx]
Some examples:
library(gpclib)
library(maptools)
library(sp)
library(RColorBrewer)
cirques.shp <- readShapePoints(file.choose(),
proj4string=CRS("+proj=longlat"))
orotl.shp <- readShapeLines(file.choose(),
proj4string=CRS("+proj=longlat"))
orstations.shp <- readShapePoints(file.choose(),
proj4string=CRS("+proj=longlat"))
orcounty.shp <- readShapePoly(file.choose(),
proj4string=CRS("+proj=longlat"))
Lattice-type plots of glaciated/non-glaciated state of cirques in Oregon
# multi-panel lattice plot
cirques.shp$Glaciated <- as.factor(ifelse(cirques.shp$Glacier=="G",1,0))
cirques.shp$Unglaciated <- as.factor(ifelse(cirques.shp$Glacier=="U",1,0))
basemap <- list("sp.lines", orotl.shp, fill=NA)
spplot(cirques.shp, c("Glaciated","Unglaciated"),
col.regions=brewer.pal(8,"Set3"),
sp.layout=list(basemap),
xlim=c(-125,-115), ylim=c(41, 47),
aspect=cos((45/360)*(2*pi)),
scales=list(draw=T), key.space="right")
Multipanel plots of climate-station data
# lattice-type plots of climate-station data
nclr <- 8
plotclr <- brewer.pal(nclr,"RdBu")
plotclr <- plotclr[nclr:1] # reorder colors if appropriate
basemap <- list("sp.lines", orotl.shp, fill=NA)
cuts=c(-30,-25,-20,-15,-10.,-5,0,5,10,15,20,25,30)
spplot(orstations.shp, c("tjul", "tjan"), col.regions=plotclr,
sp.layout=list(basemap), cuts=cuts,
aspect=cos((45/360)*(2*pi)),
scales=list(draw=T), key.space="right",
main="Temperature")
spplot(orstations.shp, c("tann"), col.regions=plotclr,
sp.layout=list(basemap), cuts=cuts,
aspect=cos((45/360)*(2*pi)),
scales=list(draw=T), key.space="right",
main="Mean July Temperature")