I downloaded the polygons for the contiguous United States from the tidycensus
package. However, due to mapping needs, I would like to remove the outline of the US from the polygon, leaving the internal state borders only. Here is my code:
library(tidyverse)
library(tidycensus)
library(tigris)
library(tmap)
library(sf)
`%notin%` <- Negate(`%in%`)
acs_vars <- c(pop_total = "B00001_001",
age_total = "B01001_001")
us = get_acs(
geography = "state",
variables = acs_vars,
geometry = TRUE,
output = "wide",
year= 2018
)
contig_48 = us %>% filter(NAME %notin% c("Alaska", "Hawaii", "Puerto Rico"))
tm_shape(contig_48) + tm_polygons(col = "white")
In other words, I would like to remove the result of running st_union
on my contig_48
object. I would like to be left with contig_48
LESS the result of running st_union(contig_48)
.
I would greatly appreciate any help on this ! Thanks a lot!
So here the strategy would be:
POLYGON
of the contiguos US and cast it toLINESTRING
(in fact, this is just to create the country borders usingcontig_48
).POLYGONS
of the states toLINESTRING
and substract the buffered borders.Find here a reprex:
Created on 2022-03-23 by the reprex package (v2.0.1)