added route categories and maps

This commit is contained in:
Ben Varick 2024-11-19 13:20:20 -06:00
parent eab18f7e05
commit 72df5362b5
No known key found for this signature in database
2 changed files with 44 additions and 20 deletions

View File

@ -61,7 +61,7 @@ metro_data <- metro_raw %>%
mutate(lag_spd = (pdist - lag_pdist)/as.double(difftime(time, lag_time, units = "hours"))/5280) mutate(lag_spd = (pdist - lag_pdist)/as.double(difftime(time, lag_time, units = "hours"))/5280)
metro_summary <- metro_data %>% metro_summary <- metro_data %>%
mutate(pdist_bucket = round(pdist / 500) * 500) %>% mutate(pdist_bucket = round(pdist / 200) * 100) %>%
group_by(pdist_bucket, rt, des, pid) %>% group_by(pdist_bucket, rt, des, pid) %>%
summarise(lat = median(lat, na.rm = TRUE), summarise(lat = median(lat, na.rm = TRUE),
lon = median(lon, na.rm = TRUE), lon = median(lon, na.rm = TRUE),
@ -111,24 +111,37 @@ bbox <- c(left = min(metro_data$lon),
#get basemap #get basemap
basemap <- get_stadiamap(bbox = bbox, zoom = 13, maptype = "stamen_toner_lite") basemap <- get_stadiamap(bbox = bbox, zoom = 13, maptype = "stamen_toner_lite")
# A West
routes_categorized <- read_csv(file = "routes_categorized.csv", col_types = "cc")
quantile(segments_sf %>% filter(pid %in% c("469")) %>% pull(lag_spd), c(0,0.25, 0.5, 0.75, 1)) quantile(segments_sf %>% filter(pid %in% c("469")) %>% pull(lag_spd), c(0,0.25, 0.5, 0.75, 1))
ggmap(basemap) + for (route in unique(routes_categorized$name)){
labs(title = "Metro Route Speed", route_focus <- routes_categorized %>% filter(name == route) %>% pull(pid)
subtitle = paste0("averaged between ", ggmap(basemap) +
metro_summary %>% filter(pid %in% c("1280")) %>% pull(trip_count), labs(title = paste0("Metro Route Speed - ", route),
" bus trips - ", subtitle = paste0("averaged between ",
min(date(metro_data$time)), sum(route_counts %>% filter(pid %in% route_focus) %>% pull(route_count)),
" to ", " bus trips - ",
max(date(metro_data$time))), min(date(metro_data$time)),
x = NULL, " to ",
y = NULL) + max(date(metro_data$time))),
theme(axis.text=element_blank(), x = NULL,
axis.ticks=element_blank(), y = NULL) +
plot.caption = element_text(color = "grey")) + theme(axis.text=element_blank(),
geom_sf(data = segments_sf %>% filter(pid %in% c("1280")), axis.ticks=element_blank(),
inherit.aes = FALSE, plot.caption = element_text(color = "grey")) +
aes(color = lag_spd), geom_sf(data = segments_sf %>% filter(pid %in% route_focus),
linewidth = 1) + inherit.aes = FALSE,
scale_color_distiller(palette = "RdYlGn", direction = "reverse", limits = c(0,70), name = "Average speed\n(calculated with consecutive points)") + aes(color = lag_spd),
facet_wrap(paste0(rt, "-", des) ~ .) linewidth = 1) +
scale_color_distiller(palette = "RdYlGn", direction = "reverse", limits = c(0,70), name = "Average speed or segment\n(calculated with locations, not reported speed)")
ggsave(file = paste0("figures/",
route,
".pdf"),
title = paste0("Metro Route Speed - ", route),
device = pdf,
height = 8.5,
width = 11,
units = "in",
create.dir = TRUE)
}

11
routes_categorized.csv Normal file
View File

@ -0,0 +1,11 @@
name,pid
A_West,469
A_West,387
A_West,362
A_East,421
A_East,414
A_East,422
A_East,1277
B_North,1276
B_North,1280
B_South,503010
1 name pid
2 A_West 469
3 A_West 387
4 A_West 362
5 A_East 421
6 A_East 414
7 A_East 422
8 A_East 1277
9 B_North 1276
10 B_North 1280
11 B_South 503010