[R-sig-Geo] Overimposing one map in ssplot onto another

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Fri Jan 27 18:51:23 CET 2012


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!
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


-- 
Dimitri Liakhovitski
marketfusionanalytics.com



More information about the R-sig-Geo mailing list