This repository has been archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
README.Rmd
106 lines (81 loc) · 3.3 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
cache = FALSE,
comment = "#>",
message = FALSE,
error = FALSE,
warning = FALSE,
fig.path = "README/README-",
fig.width=7.3,
fig.height=5,
out.width = '100%'
)
```
[![Build Status](http://travis-ci.org/ropensci/gtfsr.svg?branch=master)](http://travis-ci.org/ropensci/gtfsr)
[![codecov.io](http://codecov.io/github/ropensci/gtfsr/coverage.svg?branch=master)](http://codecov.io/github/ropensci/gtfsr?branch=master)
[![](http://badges.ropensci.org/55_status.svg)](https://github.com/ropensci/onboarding/issues/55)
Description
----------
`gtfsr` is an R package for easily importing, validating, and mapping transit data that follows the [General Transit Feed Specification (GTFS)](https://developers.google.com/transit/gtfs/) format.
The `gtfsr` package provides functions for converting files following the GTFS format into a single `gtfs` data objects. A `gtfs` object can then be validated for proper data formatting (i.e. if the source data is properly structured and formatted as a GTFS feed) or have any spatial data for stops and routes mapped using `leaflet`. The `gtfsr` package also provides API wrappers for the popular public GTFS feed sharing site [TransitFeeds](https://transitfeeds.com/), allowing users quick, easy access to hundreds of GTFS feeds from within R.
Installation
-----------------
You can install this package from GitHub using the devtools package:
```
if (!require(devtools)) {
install.packages('devtools')
}
devtools::install_github('ropensci/gtfsr')
```
If you have already installed `gtfsr`, you can get the latest version by running
```
remove.packages('gtfsr')
devtools::install_github('ropensci/gtfsr')
```
If you'd like to build the accompanying vignette, then run
```
devtools::install_github('ropensci/gtfsr', build_vignettes = TRUE)
```
Example Usage
------------------
```{r readme-body}
library(gtfsr)
library(magrittr)
library(dplyr)
# set the API key
# set_api_key() # uncomment to set api key
# get the feedlist dataframe and filter out NYC subway
feedlist_df <- get_feedlist() %>%
filter(grepl('NYC Subway GTFS', t, ignore.case= TRUE))
# import NYC gtfs feed by sending the url to `import_gtfs`
NYC <- import_gtfs(feedlist_df$url_d)
# get line (routes) A and B
routes <- NYC[['routes_df']] %>%
slice(which(grepl('a|b', route_id, ignore.case=TRUE))) %>%
'$'('route_id')
# take the NYC `gtfs` object and map routes. includes stops by default.
NYC %>% map_gtfs(route_ids = routes)
# gtfs will plot ALL shapes for a given route_ids. These can be reduced using the `service_ids` option.
ids <- NYC$trips_df %>%
select(route_id, service_id, shape_id) %>%
distinct() %>%
filter(route_id %in% routes)
ids %>% head(5) # see all unique combos of ids
# lets map just the the first row
route_ids <- ids$route_id[1]
service_ids <- ids$service_id[1]
shape_ids <- ids$shape_id[1]
# lets map the specific data with some other options enabled.
NYC %>%
map_gtfs(route_ids = route_ids,
service_ids = service_ids,
shape_ids = shape_ids,
route_colors = 'green', # set the route color
stop_details = TRUE, # get more stop details on click
route_opacity = .5) # change the route opacity
```
[![ropensci_footer](http://ropensci.org/public_images/github_footer.png)](http://ropensci.org)