Skip to contents

The goal of getACS is to make it easier to work with American Community Survey data from the tidycensus package 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

Note that I don’t love the current name for this package and expect to rename it as soon as I think of a better one.

Installation

You can install the development version of getACS from GitHub with:

# install.packages("pak")
pak::pkg_install("elipousson/getACS")

Usage

The main feature of getACS is support for returning multiple tables, geographies, and years.

acs_data <- get_acs_geographies(
  geography = c("county", "state"),
  county = "Baltimore city",
  state = "MD",
  table = "B08134",
  quiet = TRUE
)

The package also includes utility functions for filtering data and selecting columns to support the creation of tables using the gt package:

tbl_data <- filter_acs(acs_data, indent == 1, line_number <= 10)
tbl_data <- select_acs_cols(tbl_data)

commute_tbl <- gt_acs(
  tbl_data,
  groupname_col = "NAME",
  column_title_label = "Commute time",
  table = "B08134"
)

as_raw_html(commute_tbl)
Commute time Est. % share
Baltimore city, Maryland
Less than 10 minutes 16,296 ± 895 7% ± 0%
10 to 14 minutes 21,181 ± 1,146 9% ± 0%
15 to 19 minutes 35,915 ± 1,531 15% ± 1%
20 to 24 minutes 39,978 ± 1,823 16% ± 1%
25 to 29 minutes 16,607 ± 1,037 7% ± 0%
30 to 34 minutes 43,503 ± 1,748 18% ± 1%
35 to 44 minutes 18,634 ± 1,018 8% ± 0%
45 to 59 minutes 20,986 ± 1,314 9% ± 1%
60 or more minutes 29,323 ± 1,492 12% ± 1%
Maryland
Less than 10 minutes 208,940 ± 3,629 8% ± 0%
10 to 14 minutes 256,188 ± 4,669 9% ± 0%
15 to 19 minutes 335,702 ± 5,492 12% ± 0%
20 to 24 minutes 348,297 ± 5,120 13% ± 0%
25 to 29 minutes 176,347 ± 3,695 6% ± 0%
30 to 34 minutes 410,994 ± 6,082 15% ± 0%
35 to 44 minutes 257,995 ± 3,772 9% ± 0%
45 to 59 minutes 328,160 ± 4,584 12% ± 0%
60 or more minutes 402,049 ± 5,745 15% ± 0%
Source: 2017-2021 ACS 5-year Estimates, Table B08134.

The gt_acs_compare() function also allows side-by-side comparison of geographies:

commute_tbl_compare <- gt_acs_compare(
  tbl_data,
  column_title_label = "Commute time",
  table = "B08134"
)

as_raw_html(commute_tbl_compare)
Commute time Baltimore city, Maryland Maryland
Est. % share Est. % share
Less than 10 minutes 16,296 ± 7% 7% ± 8% 208,940 8%
10 to 14 minutes 21,181 ± 9% 9% ± 9% 256,188 9%
15 to 19 minutes 35,915 ± 15% 15% ± 12% 335,702 12%
20 to 24 minutes 39,978 ± 16% 16% ± 13% 348,297 13%
25 to 29 minutes 16,607 ± 7% 7% ± 6% 176,347 6%
30 to 34 minutes 43,503 ± 18% 18% ± 15% 410,994 15%
35 to 44 minutes 18,634 ± 8% 8% ± 9% 257,995 9%
45 to 59 minutes 20,986 ± 9% 9% ± 12% 328,160 12%
60 or more minutes 29,323 ± 12% 12% ± 15% 402,049 15%
Source: 2017-2021 ACS 5-year Estimates, Table B08134.

The package also includes several simple functions to support creating plots with the ggplot2 package:

plot_data <- filter_acs(acs_data, indent == 1, line_number > 10)
plot_data <- select_acs_cols(plot_data)

plot_data |>
  fmt_acs_county(state = "Maryland") |>
  ggplot(aes(x = perc_estimate, y = column_title, fill = NAME)) +
  geom_col(position = "dodge", alpha = 0.75) +
  scale_x_acs_percent() +
  scale_fill_viridis_d() +
  theme_minimal() +
  theme(legend.position = "top") +
  labs_acs_survey(
    y = "Means of transportation to work",
    fill = "Geography",
    table = acs_data$table_id
  )

For more information on working with Census data in R read the book Analyzing US Census Data: Methods, Maps, and Models in R (February 2023).

  • {easycensus}: Quickly Extract and Marginalize U.S. Census Tables
  • {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}: A set of convenience functions, functions for working with ACS data via tidycensus
  • {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}: A R package for loading and working with the US Census CTPP survey data.
  • {lehdr}: a package to grab LEHD data in support of city and regional planning economic and transportation analysis
  • {mapreliability}: A R package for map classification reliability calculator
  • Studying Neighborhoods With Uncertain Census Data: Code to create and visualize demographic clusters for the US with data from the American Community Survey
  • census-data-aggregator: A Python library from the L.A. Times data desk to help “combine U.S. census data responsibly”
  • 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())