I'm trying to create a map that shows the coverage of proprietary data (shapefile). Basically, the outcome will show how much of the contiguous USA is covered by the data. I used st_intersection
, but it only keeps "matched" rows. Is there a way I can keep the "unmatched" rows as well so that I can indicate which area is "NA"?
Here's a reproducible example. Suppose I have a subset of zip code maps in DC area ("zip") and the rest of the DC area zip code map is not available (of course this is not true in reality, but it's the problem I face with actual data). When I use dc_zip, only the matched rows are plotted. What I want instead is (partly) achieved by plotting the entire polygon of DC first and plotting the zip code on top of it. Here, I can split up DC into the area with zip code map created and zip code map not drawn. Is this the best approach?
library(USAboundaries)
library(sf)
library(dplyr)
library(tigris)
library(tmap)
dc <- USAboundaries::us_states() %>% filter(statefp == "11") %>% st_transform(crs = 4269)
zip <- tigris::zctas(starts_with = "2000", class = "sf")
dc_zip <- st_intersection(zip, dc)
tm_shape(dc_zip) + tm_polygons() # drops unmatched rows
tm_shape(dc) + tm_polygons("grey80") + tm_shape(zip) + tm_polygons("green") # keeps unmatched rows
Any comments are appreciated!