我在使用关岛和马里亚纳群岛的底格里斯形状文件时遇到问题:
- 底格里斯河关岛地图没有提供城市信息,但许多人口普查数据集包括关岛的城市。底格里斯河文件包括对市政当局的引用。任何人都可以推荐关岛自治市多边形/形状文件的另一个来源吗?
- 使用底格里斯河中的县函数无法正确下载马里亚纳群岛。我已经包括了我的解决方法,但我希望能够直接访问此信息。
.
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()
关
- 岛问题的解决方案是使用"地点"功能。
- 错误已修复。底格里斯河的维护者凯尔·沃克(Kyle Walker)更新了该应用程序,以回应这篇文章和相关推文。请参阅推文。