-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
152 lines (115 loc) · 5.8 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
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%"
)
```
# getACS
<!-- badges: start -->
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://opensource.org/licenses/MIT)
[](https://www.repostatus.org/#wip)
<!-- badges: end -->
The goal of getACS is to make it easier to work with [American Community Survey data](https://www.census.gov/programs-surveys/acs) from the [tidycensus package](https://walker-data.com/tidycensus/) by Kyle Walker and others.
This package includes:
- Functions that extend `tidycensus::get_acs()` to support multiple tables, geographies, or years
- Functions for creating formatted tables from ACS data using the [gt package](https://gt.rstudio.com/)
As of April 2024, this package uses a development version of `{tigris}`, available at <https://github.com/elipousson/tigris>.
## Installation
You can install the development version of getACS from [GitHub](https://github.com/) with:
``` r
# install.packages("pak")
pak::pkg_install("elipousson/getACS")
```
## Usage
```{r setup}
library(getACS)
library(gt)
library(ggplot2)
```
The main feature of `{getACS}` is support for returning multiple tables, geographies, and years.
```{r}
acs_data <- get_acs_geographies(
geography = c("county", "state"),
county = "Baltimore city",
state = "MD",
table = "B08134",
year = 2022,
quiet = TRUE
)
```
The package also includes utility functions for filtering data and selecting columns to support the creation of tables using the `{gt}` package:
```{r}
tbl_data <- filter_acs(acs_data, indent == 1, line_number <= 10)
tbl_data <- select_acs(tbl_data)
commute_tbl <- gt_acs(
tbl_data,
groupname_col = "NAME",
column_title_label = "Commute time",
table = "B08134"
)
as_raw_html(commute_tbl)
```
The `gt_acs_compare()` function also allows side-by-side comparison of geographies:
```{r}
commute_tbl_compare <- gt_acs_compare(
data = tbl_data,
id_cols = "column_title",
column_title_label = "Commute time",
table = "B08134"
)
as_raw_html(commute_tbl_compare)
```
`gt_acs_compare_vars()` is a variant on `gt_acs_compare()` where the default values support comparisons with values in columns and geographical areas in rows:
```{r}
commute_tbl_compare_vars <- acs_data |>
filter_acs(indent == 1, line_number > 10) |>
gt_acs_compare_vars(
table = acs_data$table_id
)
as_raw_html(commute_tbl_compare_vars)
```
The package also includes several functions to support creating plots with the `{ggplot2}` package including `geom_acs_col()` and `labs_acs_survey()`:
```{r}
plot_data <- acs_data |>
filter_acs(indent == 1, line_number > 10) |>
select_acs() |>
fmt_acs_county(state = "Maryland")
plot_data |>
ggplot() +
geom_acs_col(
fill = "NAME",
position = "dodge",
color = NA,
alpha = 0.75,
perc = TRUE,
errorbar_params = list(position = "dodge", linewidth = 0.25)
) +
scale_y_discrete("Means of transportation to work") +
scale_fill_viridis_d("Geography") +
labs_acs_survey(
.data = acs_data
) +
theme_minimal()
```
The `geom_acs_col()` function calls `geom_acs_errorbar()` (passing the `errorbar_params` argument as additional parameters) and `scale_x_acs()` or `scale_y_acs()` (depending on whether `orientation = "y"` or the default value of `NA`).
For more information on working with Census data in R [read the book *Analyzing US Census Data: Methods, Maps, and Models in R*](https://walker-data.com/census-r) (February 2023).
## Related projects
### Related R packages and analysis projects
- [{easycensus}](https://github.com/CoryMcCartan/easycensus): Quickly Extract and Marginalize U.S. Census Tables
- [{cwi}](https://ct-data-haven.github.io/cwi/): Functions to speed up and standardize Census ACS data analysis for multiple staff people at DataHaven, preview trends and patterns, and get data in more layperson-friendly
- [{camiller}](https://camille-s.github.io/camiller/): A set of convenience functions, functions for working with ACS data via `{tidycensus}`
- [{psrccensus}](https://psrc.github.io/psrccensus/): A set of tools developed for PSRC (Puget Sound Regional Council) staff to pull, process, and visualize Census Data for geographies in the Central Puget Sound Region.
- [{CTPPr}](https://github.com/Westat-Transportation/CTPPr): A R package for loading and working with the US Census CTPP survey data.
- [{lehdr}](https://github.com/jamgreen/lehdr): a package to grab LEHD data in support of city and regional planning economic and transportation analysis
- [{mapreliability}](https://github.com/austensen/mapreliability): A R package for map classification reliability calculator
- [Studying Neighborhoods With Uncertain Census Data](https://github.com/geoss/acs_demographic_clusters): Code to create and visualize demographic clusters for the US with data from the American Community Survey
### Related Python libraries
- [census-data-aggregator](https://github.com/datadesk/census-data-aggregator): A Python library from the L.A. Times data desk to help "combine U.S. census data responsibly"
- [census-table-metadata](https://github.com/censusreporter/census-table-metadata): Tools for generating metadata about tables and fields in a Census release based on sequence lookup and table shell files. (Note: the pre-computed data from this repository is used to label ACS data by `label_acs_metadata()`)