options(tigris_class = "sf")
options(tigris_use_cache = TRUE)
# tigris_cache_dir("/Users/statkclee/swc/tmp")
tx_counties <- counties(class = 'sf', state = 'TX', cb = TRUE, year = 2018)
leaflet(tx_counties) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor = "white",
color = "black",
weight = 0.5)
bank_sf <- bank_df %>%
st_as_sf(coords = c("location_lon", "location_lat"), crs = 4269)
bank_branches <- bank_df %>% count(county) %>% pull(county)
tx_counties <- tx_counties %>%
mutate(branch_tf = NAME %in% bank_branches)
ggplot() +
geom_sf(data = tx_counties, aes(fill = branch_tf)) +
geom_point(data=bank_df, aes(x=location_lon, y=location_lat),
size = 2) +
theme_bw() +
labs(fill = "Spirit of Texas Branches")
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = tx_counties,
fillColor = "white",
color = "black",
weight = 0.5) %>%
addMarkers(data = bank_df, lng=~location_lon, lat = ~location_lat,
popup = ~ as.character(glue("<strong> {offname} </strong> <br>
· Run Date: {rundate}")))