Chapter 2 GTFS Data

The General Transit Feed Specification ( GTFS ) is the de facto data standard for transit schedules. It was started by Portland’s Transit Agency TriMet and Google.

Because it is based on a table data structure, GTFS plays well with R and with the tidyverse.

And because its so prolific, its a fun way to learn more about R and R Studio.

2.1 Reading GTFS Data into R

tidytransit is a package for working with General Transit Feed Specification (GTFS) data in R.

2.2 Installation

2.2.1 tidytransit

Please see the install instructions here:

2.3 Reading from URL’s

Fetch data for a bus system in Accra, Ghana from GitHub.

Inspect the available tables imported by read_gtfs:

##  [1] "agency_df"          "calendar_df"        "feed_info_df"      
##  [4] "frequencies_df"     "routes_df"          "shapes_df"         
##  [7] "stop_times_df"      "stops_df"           "trips_df"          
## [10] "validation"         "stops_frequency_df" "stops_sf"          
## [13] "routes_sf"

2.4 Finding More GTFS Data

Government sources are also a great, since they produce the data.

Transitfeeds is a also a great resource for finding GTFS feeds. For convenience, a list of the feeds from it is cached in the tidytransit package with the name feedlist_df.

2.4.2 By Geography

If you have the sf and mapview packages installed, you can also search by location:

## Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3