Drawing thicker state borders and thiner county borders for US map using GADM shapefile

这一生的挚爱 提交于 2019-12-11 14:59:31

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/59117165/drawing-thicker-state-borders-and-thiner-county-borders-for-us-map-using-gadm-sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!