Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

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

$
0
0

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: enter image description here 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: enter image description here

Any suggestion on how to achieve this is appreciated.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>