@@ -132,6 +132,22 @@ trips <- tm_trip_metrics(
132132 agg = "daily",
133133 line = "line-red"
134134)
135+
136+ # How many trips were scheduled to run each day
137+ scheduled <- tm_scheduled_service(
138+ start_date = "2024-01-01",
139+ end_date = "2024-01-31",
140+ route_id = "Red",
141+ agg = "daily"
142+ )
143+
144+ # Total revenue service hours each day on the Red Line
145+ hours <- tm_service_hours(
146+ start_date = "2024-01-01",
147+ end_date = "2024-01-31",
148+ agg = "daily",
149+ line_id = "Red"
150+ )
135151```
136152
137153** Available line IDs:**
@@ -144,7 +160,7 @@ trips <- tm_trip_metrics(
144160| Green Line | ` "line-green" ` |
145161| Commuter | ` "line-cr" ` |
146162
147- ## Step 6 : Turn the result into a data frame
163+ ## Step 8 : Turn the result into a data frame
148164
149165The API gives back a list, but most R analysis tools (like ` ggplot2 ` ) prefer a
150166** data frame** . Here's the easiest way to convert:
@@ -167,7 +183,7 @@ head(ridership_df)
167183> ` do.call(rbind, lapply(ridership_raw, as.data.frame)) ` — it's a bit more
168184> verbose but handles some tricky list shapes.
169185
170- ## Step 7 : Make a quick plot
186+ ## Step 9 : Make a quick plot
171187
172188Once you have a data frame you can plot with ` ggplot2 ` :
173189
@@ -190,11 +206,54 @@ ggplot(ridership_df, aes(x = as.Date(date), y = count)) +
190206 theme_minimal()
191207```
192208
209+ ## Step 7: Aggregate endpoints
210+
211+ The aggregate endpoints return long-run averages rather than individual trip
212+ events — useful for trend analysis over weeks or months.
213+
214+ ``` {r aggregate, eval = FALSE}
215+ # Average travel time from Park Street to Davis, by date
216+ travel_agg <- tm_aggregate_travel_times(
217+ from_stop = "70076",
218+ to_stop = "70064",
219+ start_date = "2024-01-01",
220+ end_date = "2024-01-31"
221+ )
222+
223+ # Same data via the v2 endpoint (returns by_date and by_time breakdowns)
224+ travel_agg2 <- tm_aggregate_travel_times2(
225+ from_stop = "70076",
226+ to_stop = "70064",
227+ start_date = "2024-01-01",
228+ end_date = "2024-01-31"
229+ )
230+
231+ # Average headways at a stop over a date range
232+ headways_agg <- tm_aggregate_headways(
233+ stop = "70061",
234+ start_date = "2024-01-01",
235+ end_date = "2024-01-31"
236+ )
237+
238+ # Average dwell times at a stop over a date range
239+ dwells_agg <- tm_aggregate_dwells(
240+ stop = "70061",
241+ start_date = "2024-01-01",
242+ end_date = "2024-01-31"
243+ )
244+ ```
245+
246+ > ** Tip:** The v2 travel times endpoint (` tm_aggregate_travel_times2 ` ) is used
247+ > in the Red Line Analysis vignette for a worked plotting example.
248+
193249## Recap: the functions at a glance
194250
195251| Function | What it returns | Needs |
196252| ---| ---| ---|
197253| ` tm_healthcheck() ` | API status | nothing |
254+ | ` tm_git_id() ` | Server git commit SHA | nothing |
255+ | ` tm_time_predictions() ` | Live time predictions | nothing |
256+ | ` tm_service_ridership_dashboard() ` | System-wide ridership summary | nothing |
198257| ` tm_facilities() ` | All MBTA stations | nothing |
199258| ` tm_routes() ` | All available routes by mode | nothing |
200259| ` tm_stops(route_id) ` | Stop IDs for a route | route ID |
@@ -205,9 +264,13 @@ ggplot(ridership_df, aes(x = as.Date(date), y = count)) +
205264| ` tm_ridership(start, end) ` | Ridership counts | date range |
206265| ` tm_trip_metrics(start, end, agg, line) ` | Trip performance | date range + line |
207266| ` tm_line_delays(start, end, line) ` | Delay summaries | date range + line |
267+ | ` tm_scheduled_service(start, end, agg) ` | Scheduled trip counts | date range + agg |
268+ | ` tm_service_hours(start, end, agg, line_id) ` | Revenue service hours | date range + agg + line |
208269| ` tm_speed_restrictions(line_id, date) ` | Slow zones | line + date |
209270| ` tm_aggregate_travel_times(...) ` | Long-run travel time trends | stop pair + range |
271+ | ` tm_aggregate_travel_times2(...) ` | Long-run travel times (v2, with by_date/by_time) | stop pair + range |
210272| ` tm_aggregate_headways(...) ` | Long-run headway trends | stop + range |
273+ | ` tm_aggregate_dwells(...) ` | Long-run dwell time trends | stop + range |
211274
212275Next, check out the ** Red Line Analysis** vignette for a full worked example
213276that goes from raw API data to a polished chart.
0 commit comments