Skip to content
Prev 14014 / 29559 Next

Coloring Canada provinces in raster

Dear map-gurus,
I've made some progress based on one post I found, but now I am stuck.
I was able to group Canadian admin units into 6 groups so that each
group has the same color:

# Getting the data:
library(raster)
can2<-getData('GADM', country="CAN", level=2)
class(can2)

# Creating my (artificial) groupings 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" and calling this new
variables "groups"
can2 at data[["groups"]]<-groups

# Plotting:
spplot(can2,"groups")

Questions that I am still not sure how to address:
How can I use MY colors instead of the default colors? In fact, I
don't want heat map, I need 6 separate colors...
Can I remove the legend from the plot?
Can I eliminate borders between counties but have borders between
Canadian Provinces (like in the US example below)?
I.e., only borders from the plot for can1:
can1<-getData('GADM', country="CAN", level=1)
plot(can1)

Thanks a lot!
Dimitri



On Thu, Jan 26, 2012 at 1:14 PM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote: