knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) library(tidyverse)
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.
You can install the development version of ctpp_flows from GitHub with:
# install.packages("devtools") devtools::install_github("gregmacfarlane/ctpp_flows")
After installing the library, the ctpp_flows
dataset is available as a tibble
lazy-loaded into your environment.
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}$$
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.
# 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.