Overimposing one map in ssplot onto another
On Fri, 27 Jan 2012, Dimitri Liakhovitski wrote:
Hello! I have 2 maps - both created in ssplot and both identical in terms of outline. Is there any way to superimpose Map1 (which has black borders between Canadian provinces) onto Map2 (which is also a map of Canada)? Thanks a lot for your hints!
See the sp.layout= argument to spplot() - here:
spl <- list("sp.lines", as(can1, "SpatialLines"), lwd=0.4)
should give what you need, as lines plot over polygons, but not the
opposite.
Roger
Dimitri
### A. Reading in Canada data at the province and then at the county level:
library(raster)
getData('ISO3') ?# Canada's code is "CAN"
can1<-getData('GADM', country="CAN", level=1)
can2<-getData('GADM', country="CAN", level=2)
### B. Creating Map1- with borders between provinces:
can1 at data[["groups"]]<-1 ? # want all provinces to have the same
color, but ideally I'd like the whole map to be transparent.
can1 at data$groups<-as.factor(can1 at data$groups)
spplot(can1,zcol="groups",col.regions="white",colorkey = FALSE,
lwd=.4, ?# col='white',
?par.settings = list(axis.line = list(col='transparent')))
### C. Creating Map2- with borders between colored counties:
# Creating an (artificial) grouping of Canadian admin units:
nrofunits<-length(can2$NAME_2)
groups<-c(rep(1:6,(nrofunits %/%
6)),rep(1,5))[order(c(rep(1:6,(nrofunits %/% 6)),rep(1,5)))]
# adding values (grouping values) to "data":
can2 at data[["groups"]]<-groups
can2 at data$groups<-as.factor(can2 at data$groups)
classcolors <- rainbow(6)
spplot(can2,zcol="groups",col.regions=classcolors,colorkey =
FALSE,lwd=.4,col='white',
?par.settings = list(axis.line = list(col='transparent')))
--
Dimitri Liakhovitski
marketfusionanalytics.com
Roger Bivand Department of Economics, NHH Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no