Created
January 22, 2023 17:15
-
-
Save idshklein/dc0f2433ce9f572518dd9a678d3088eb 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
pacman::p_load(gtfstools,lubridate,tidyverse) | |
gtfs <- read_gtfs("C:/Users/idshk/Downloads/israel-public-transportation (5).zip") | |
stop_city <- read_delim("C:/Users/idshk/Downloads/e873e6a2-66c1-494f-a677-f5e77348edb0.csv",delim = "|") | |
dfq <- gtfs$stop_times %>% | |
left_join(gtfs$stops, by = "stop_id") %>% | |
mutate(stop_code = as.numeric(stop_code)) %>% | |
left_join(stop_city, by = c("stop_code"="StationId")) %>% | |
distinct(trip_id,stop_code,CityName) %>% | |
left_join(gtfs$trips, by = "trip_id") %>% | |
left_join(gtfs$routes, by = "route_id") %>% | |
distinct(CityName,route_short_name) %>% | |
filter(route_short_name != "",!is.na(CityName)) %>% | |
arrange(CityName,route_short_name) %>% | |
add_count(CityName) | |
dfq %>% | |
mutate(route_short_name = as.numeric(route_short_name)) %>% | |
filter(!is.na(route_short_name)) %>% | |
as_tibble() %>% | |
arrange(CityName,route_short_name) %>% | |
group_by(CityName) %>% | |
mutate(diff1 =lead(route_short_name)-route_short_name, | |
diff2 = lag(cumsum(diff1 != 1))) %>% | |
group_by(CityName,diff2) %>% | |
add_count() %>% | |
ggplot(aes(x=route_short_name,y=CityName)) + | |
geom_point() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment