使用 GADM shapefile 为美国地图绘制更粗的州边界和更细的县边界 [英] Drawing thicker state borders and thiner county borders for US map using GADM shapefile

查看:101
本文介绍了使用 GADM shapefile 为美国地图绘制更粗的州边界和更细的县边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在可以看出,尽管五大湖地区不再使用颜色编码,但州边界仍然存在(红色箭头).我想要一个像下面这样的图,其中州被土地边界分隔,没有州边界跨越湖泊区域:

对于如何实现这一目标的任何建议,我们深表感谢.

解决方案

您甚至不需要 us0 (国界)和 us1 (国界).这些已经存在于 us2 中.您可以绘制所需的输出,如下所示:

  us0<-sf :: st_union(us2)us1<-us2%&%;%group_by(NAME_1)%>%总结() 

和您绘制的地块:

 #跨三个级别的最终情节p <- 大陆2 +geom_sf(数据= us1,填充= NA,尺寸= 1.5,颜色=黑色")+coord_sf(crs = st_crs(2163),xlim = c(-2500000,2500000),ylim = c(-2300000,730000))+geom_sf(数据= us0,填充= NA,尺寸= 1.5,颜色=黑色")+coord_sf(crs = st_crs(2163),xlim = c(-2500000,2500000),ylim = c(-2300000,730000))+指南(填充= F)p 

希望有帮助.

I have an earlier post here on drawing US maps using shape file from GADM while at the same time removing color mapping onto the Great Lakes region. The issue was solved following suggestion by @Majid.

Now, I further want thicker state boders and thinner county borders. I did so by plotting county-level choropleth map first and then add additional lays of non-filled state/nation-level border:

library(sf)
library(tidyverse)
library(RColorBrewer) #for some nice color palettes

# US map downloaded from https://gadm.org/download_country_v3.html

# National border
us0 <- st_read("<Path>\\gadm36_USA_0.shp")
# State border
us1 <- st_read("<Path>\\gadm36_USA_1.shp")
# County border
us2 <- st_read("<Path>\\gadm36_USA_2.shp")

# Remove the Great Lakes
# retrieving the name of lakes and excluding them from the sf 
all.names = us2$NAME_2
patterns = c("Lake", "lake")

lakes.name <- unique(grep(paste(patterns, collapse="|"), 
                     all.names, 
                     value=TRUE, ignore.case = TRUE))

# Pick the Great Lakes
lakes.name <- lakes.name[c(4, 5, 7, 10, 11)]

`%notin%` <- Negate(`%in%`)
us2 <- us2[us2$NAME_2 %notin% lakes.name, ]

# National level
mainland0 <- ggplot(data = us0) +
    geom_sf(fill = NA, size = 0.3, color = "black") +
    coord_sf(crs = st_crs(2163), 
             xlim = c(-2500000, 2500000), 
             ylim = c(-2300000, 730000)) 

# State level
mainland1 <- ggplot(data = us1, size = 0.3, color = "black") +
    geom_sf(fill = NA) +
    coord_sf(crs = st_crs(2163), 
             xlim = c(-2500000, 2500000), 
             ylim = c(-2300000, 730000))

# County level
mainland2 <- ggplot(data = us2) +
    geom_sf(aes(fill = NAME_2), size = 0.1, color = "black") +
    coord_sf(crs = st_crs(2163), 
             xlim = c(-2500000, 2500000), 
             ylim = c(-2300000, 730000))+
    guides(fill = F)

# Final plot across three levels
p <- mainland2 +
    geom_sf(data = us1, fill = NA, size = 0.3, color = "black") +
    coord_sf(crs = st_crs(2163), 
             xlim = c(-2500000, 2500000), 
             ylim = c(-2300000, 730000)) +
    geom_sf(data = us0, fill = NA, size = 0.3, color = "black") +
    coord_sf(crs = st_crs(2163), 
             xlim = c(-2500000, 2500000), 
             ylim = c(-2300000, 730000)) +
    guides(fill = F)

The image generated is as follows: It can be seen that although the Great Lakes regions is no longer color coded, the state borders still exist (red arrows). I want a figure like below where states are separated by land boundaries and no state border crosses the lake region:

Any suggestion on how to achieve this is appreciated.

解决方案

You don't even need us0 (national border) and us1 (State border). These already exist in us2. You can plot your desired output as below:

us0 <- sf::st_union(us2)
us1 <- us2 %>% 
           group_by(NAME_1)%>% 
           summarise()

and the plot you map:

# Final plot across three levels
p <- mainland2 +
  geom_sf(data = us1, fill = NA, size = 1.5, color = "black") +
  coord_sf(crs = st_crs(2163), 
           xlim = c(-2500000, 2500000), 
           ylim = c(-2300000, 730000)) +
  geom_sf(data = us0, fill = NA, size = 1.5, color = "black") +
  coord_sf(crs = st_crs(2163), 
           xlim = c(-2500000, 2500000), 
           ylim = c(-2300000, 730000)) +
  guides(fill = F)

p

Hope that helps.

这篇关于使用 GADM shapefile 为美国地图绘制更粗的州边界和更细的县边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆