/
README.Rmd
78 lines (58 loc) · 1.97 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(tidyverse)
```
# ctppflows
<!-- badges: start -->
<!-- badges: end -->
The goal of ctppflows is to provide tract level home-work flow data from the
Census Transportation Planning Package (CTPP) in a much more convenient format
for R users, particularly those without a Microsoft Access license.
The entire tract dataset is included in the package as a documented R object,
and the package also contains helper functions for properly calculating aggregate
flows and their margins of error.
## Installation
You can install the development version of ctpp_flows from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("gregmacfarlane/ctpp_flows")
```
## Example
After installing the library, the `ctpp_flows` dataset is available as a tibble
lazy-loaded into your environment.
```{r example}
library(ctppflows)
# load
ctpp_flows
```
The `aggregate_flows` function will aggregate the flows to a state or county.
The aggregated margin of error is computed as
$$ \sqrt{\sum_{i=1}^N MOE_i^2}$$
```{r aggregate}
aggregate_flows("state")
```
The results can then be passed into other R formatting functions. For instance,
we could make a plot of where workers into Salt Lake County reside.
```{r pressure}
# get workplaces in salt lake county
sl_workers <- ctpp_flows %>%
mutate(county = str_c(get_state(workplace), get_county(workplace))) %>%
filter(county == "49035") %>%
filter(flow > 50) %>%
group_by(residence) %>%
summarise(flow = sum(flow))
ut_tr <- tigris::tracts("Utah", class = "sf", progress_bar = FALSE) %>%
select(GEOID) %>%
left_join(sl_workers, by = c("GEOID" = "residence"))
ggplot(ut_tr %>% filter(flow > 0), aes(fill = log(flow))) +
geom_sf() + scale_fill_viridis_b()
```