Это, безусловно, выполнимо, но без приличного набора данных мне приходилось придумывать некоторые по ходу работы.
library(tigris)
library(tidyverse)
library(sf)
# get US zipcode shapefile
# This takes a while to download
zip <- zctas(cb = TRUE)
# Transform to an sf object, and change projection
zip_sf <- st_as_sf(zip) %>%
filter(stringr::str_starts(ZCTA5CE10, '3')) %>% ## returns some of southeast US
st_transform(5070) %>%
st_simplify() %>%
st_transform(4326)
# Wholly made-up points, bufferd by 150km
regions <- tribble(
~region, ~lon, ~lat,
'one', -88, 32,
'two', -82, 28,
'three', -86, 34,
'four', -82, 31
) %>% st_as_sf(coords = c('lon', 'lat')) %>%
st_set_crs(4326) %>%
st_transform(5070) %>%
st_buffer(150000) %>%
st_transform(4326)
# Here the data is joined spatially.
# Your data should be joined (probably with a left-join)
# using the zip code columns.
joined <- st_join(zip_sf, regions, join = st_within)
ggplot(joined) +
geom_sf(aes(fill = region), size = .1) +
scale_fill_discrete(na.value = 'white')
Я использовал ggplot2 для графика, но tmap, mapview, et c должно работать так же хорошо.
![enter image description here](https://i.stack.imgur.com/xGhgq.png)