Created
August 1, 2023 20:25
-
-
Save walkerke/611db58604f46b184ac97a603c0020f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(tigris) | |
library(tidycensus) | |
library(tidyverse) | |
library(mapview) | |
library(mapboxapi) | |
library(randomNames) | |
options(tigris_use_cache = TRUE) | |
denton <- counties(cb = TRUE) %>% | |
filter(GEOID == "48121") %>% | |
erase_water() | |
customers <- st_sample(denton, size = 20) %>% | |
st_coordinates() | |
# Use set.seed() if you want the same names every time | |
customer_table <- tibble( | |
name = randomNames(n = 20), | |
longitude = customers[,1], | |
latitude = customers[,2] | |
) | |
customer_sf <- customer_table %>% | |
st_as_sf(coords = c("longitude", "latitude"), | |
crs = 4326) | |
customer_buffers <- customer_sf %>% | |
st_transform(26914) %>% | |
st_buffer(5000) | |
mapview(customer_buffers) | |
customer_drivetimes <- customer_sf %>% | |
mb_isochrone(time = 10, profile = "driving", | |
id_column = "name") | |
mapview(customer_drivetimes) | |
denton_income <- get_acs( | |
geography = "tract", | |
variables = "B19013_001", | |
state = "TX", | |
county = "Denton", | |
geometry = TRUE | |
) %>% | |
select(tract_income = estimate) %>% | |
st_transform(st_crs(customer_sf)) | |
customers_with_income <- customer_sf %>% | |
st_join(denton_income) | |
customers_with_income |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment