map_zone_categories <- function(){
taxi_zones <- sf::st_read("../gozentosun2021_shapefiles/taxi_zones/taxi_zones.dbf") %>%
dplyr::select(zone_id = .data$locationid)
zones_with_bikes <- sparklyr::sdf_sql(sc, 'SELECT * FROM station_zone') %>%
dplyr::collect() %>%
dplyr::distinct(zone_id)
df <- taxi_zones %>%
dplyr::mutate(category = dplyr::case_when(
zone_id %in% drop_zones ~ "Excluded",
zone_id %in% zones_with_bikes$zone_id ~ "Has bike stations",
TRUE ~ "Does not have a bike station"
)) %>%
dplyr::mutate(category = factor(category,
levels = c("Excluded", "Does not have a bike station", "Has bike stations")))
p <- tmap::tm_shape(df) +
tmap::tm_borders(col = "grey99", lwd = 0.5, lty = "solid", alpha = NA) +
tmap::tm_polygons(col = "category", pal = c("#ce6a6b", "#bed3c3", "#4a919e"),
showNA= FALSE,
colorNA= "grey90",
title = "") +
tmap::tm_layout(frame = FALSE, legend.position = c("center", "bottom"))
tmap::tmap_save(p, "img/zone_categories.png", height = 6, width = 8)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.