R/map_zone_categories.R

Defines functions map_zone_categories

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)

}
hktosun/gozentosun2021 documentation built on Dec. 20, 2021, 4:44 p.m.