I'm having trouble with the tigris shape files for Guam and the Mariana Islands:
- The tigris Guam map provides no municipality information however many census datasets include municipalities for Guam. The tigris documentation includes reference to the municipalities. Can anyone recommend another source for Guam municipality polygon/shapefiles?
- The Mariana Islands are not downloaded correctly using the counties function in tigris. I have included my work-around but I would prefer to be able to access this information directly.
.
library(tigris)
library(ggplot2)
library(ggthemes)
library(dplyr)
## Working Puerto Rico Map ----
# Downloads map
PR_map <- counties(72, cb = T)
# Converts shapefile for ggplot2
PR_map <- ggplot2::fortify(PR_map, region = "COUNTYFP")
# Adds random data
PR_map <- merge(PR_map, data.frame(id = unique(PR_map$id), value = rep(1:4, (length(unique(PR_map$id)) %/% 4 + 4))[1:length(unique(PR_map$id))]), by = "id")
# Plots map
ggplot(PR_map)+geom_map(map = PR_map, aes(x=long, y=lat, fill = value, map_id=id), color="white", size=0.25)+ coord_map("mercator")+ theme_map()
## Broken Guam Map (No municipalities)----
# Downloads map
GU_map <- counties(66, cb = T)
# Converts shapefile for ggplot2
GU_map <- ggplot2::fortify(GU_map, region = "COUNTYFP")
# Adds random data
GU_map <- merge(GU_map, data.frame(id = unique(GU_map$id), value = rep(1:4, (length(unique(GU_map$id)) %/% 4 + 4))[1:length(unique(GU_map$id))]), by = "id")
# Plots map
ggplot(GU_map)+geom_map(map = GU_map, aes(x=long, y=lat, fill = value, map_id=id), color="white", size=0.25)+ coord_map("mercator")+ theme_map()
## Broken Call for Mariana Islands
# Does not download Mariana Islands, instead it downloads the entire United States and Territories
USA_map <- counties(69, cb = T)
# My work around is to subset to the appropriate region:
MI_map <- subset(USA_map, USA_map$STATEFP == "69")
# Converts shapefile for ggplot2
MI_map <- ggplot2::fortify(MI_map, region = "COUNTYFP")
# Adds random data
MI_map <- merge(MI_map, data.frame(id = unique(MI_map$id), value = rep(1:4, (length(unique(MI_map$id)) %/% 4 + 4))[1:length(unique(MI_map$id))]), by = "id")
# Plots map (The hex turns the map sideways for better viewing.)
ggplot(MI_map)+geom_map(map = MI_map, aes(x=long, y=lat, fill = value, map_id=id), color="white", size=0.25)+ coord_map("hex")+ theme_map()