Skip to content

Instantly share code, notes, and snippets.

@rafapereirabr
Created August 31, 2022 17:00
Show Gist options
  • Save rafapereirabr/4ca1e340f82ef4a91a777f1a57e035f1 to your computer and use it in GitHub Desktop.
Save rafapereirabr/4ca1e340f82ef4a91a777f1a57e035f1 to your computer and use it in GitHub Desktop.
Visualizing transit frequencies from GTFS data
library(gtfstools)

# read gtfs
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)

# merge trips and freq
trip_df <- merge(gtfs$trips, gtfs$frequencies)

# get add spatial info
shapes_sf <- gtfstools::convert_shapes_to_sf(gtfs)
trip_sf <- merge(shapes_sf, trip_df)


# Static plot
library(ggplot2)
ggplot() +
  geom_sf(data=trip_sf, aes(color=headway_secs, size=headway_secs), alpha=.4) +
  scale_size("Headway", range = c(.1,2), guide="none") +
  labs(color='Headway') +
  theme_void()

# interactive plot
mapview::mapview(trip_sf, z='headway_secs')
@rafapereirabr
Copy link
Author

Screenshot 2022-08-31 121807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment