I am trying to create a choropleth map of British Columbia to map driving distances for particular services.
I successfully created a similar map based on previous examples but cannot seem to get the map for BC.
I downloaded the Canada province shapefile and the census divisions shapefiles from this web site
# load packages
library(rgdal)
library(ggplot2)
library(dplyr)
###LOAD SHAPE FILES####
canada_raw <- readOGR(dsn = ".", layer = "gcd_000b11a_e") #canada census subdivision file
province <- readOGR(dsn = ".", layer = "lpr_000b16a_e") #canada province shapefile
####work with the region data####
canada_map <- fortify(canada_raw) #Fortify the data
map_areas <- data.frame(id=rownames(canada_raw@data),
regionid = canada_raw@data$CDUID,
regionname = canada_raw@data$CDNAME,
prname = canada_raw@data$PRNAME)
merged <- merge(canada_map, map_areas, by = "id") #merge by ID
bc_areas <- subset(merged, merged$prname=="British Columbia / Colombie-Britannique") #subset for BC
####PROVINCE####
province <- province[province$PRNAME=="Colombie-Britannique"]
province <- fortify(province)
####MAP####
merged$id2 <- as.numeric(merged$id) #convert to numeric to fill the groups
ggMap <- ggplot(data=bc_areas, aes(x=long, y=lat, group = group))
ggMap <- ggMap + geom_polygon(aes(fill = id2))
ggMap <- ggMap + geom_path(data=province, aes(x=long,y=lat,group=group))
ggMap <- ggMap + scale_fill_gradient(name="Title", low = "red4",
high = "white")
ggMap <- ggMap + coord_equal()
ggMap
I just get a blank map (even after 30 minutes of waiting). Thank you so much!