View source: R/multi_geo_fetch.R
multi_geo_acs | R Documentation |
Fetch a data table from the ACS via tidycensus
with your choice of geographies at multiple levels. For geographies made of aggregates, i.e. neighborhoods made of tracts or regions made of towns, the returned table will have estimates summed and margins of error calculated for the whole area. Any geographic levels that are null will be excluded.
multi_geo_acs(
table,
year = 2022,
towns = "all",
regions = NULL,
counties = "all",
state = "09",
neighborhoods = NULL,
tracts = NULL,
blockgroups = NULL,
pumas = NULL,
msa = FALSE,
us = FALSE,
new_england = TRUE,
nhood_name = "name",
nhood_geoid = NULL,
nhood_weight = "weight",
survey = c("acs5", "acs1"),
verbose = TRUE,
key = NULL,
sleep = 0,
...
)
table |
A string giving the ACS table number. |
year |
The year of the ACS table; currently defaults 2022 (most recent available). |
towns |
A character vector of names of towns to include; |
regions |
A named list of regions with their town names (defaults |
counties |
A character vector of names of counties to include; |
state |
A string: either name or two-digit FIPS code of a US state. Required; defaults |
neighborhoods |
A data frame with columns for neighborhood name, GEOID of either tracts or block groups, and weight, e.g. share of each tract assigned to a neighborhood. If included, weighted sums and MOEs will be returned for neighborhoods. Try to match the formatting of the built-in neighborhood tables. |
tracts |
A character vector of 11-digit FIPS codes of tracts to include, or |
blockgroups |
A character vector of 12-digit FIPS codes of block groups to include, or |
pumas |
A character vector of 7-digit FIPS codes of public use microdata areas (PUMAs) to include, or |
msa |
Logical: whether to fetch New England states' metropolitan statistical areas. Defaults |
us |
Logical: whether to fetch US-level table. Defaults |
new_england |
Logical: if |
nhood_name |
String giving the name of the column in the data frame |
nhood_geoid |
String giving the name of the column in |
nhood_weight |
String giving the name of the column in |
survey |
A string: which ACS estimate to use. Defaults to 5-year ( |
verbose |
Logical: whether to print summary of geographies included. Defaults |
key |
String: Census API key. If |
sleep |
Number of seconds, if any, to sleep before each API call. This might help with the Census API's tendency to crash, but for many geographies, it could add a sizable about of time. Probably don't add more than a few seconds. |
... |
Additional arguments to pass on to |
This function essentially calls tidycensus::get_acs()
multiple times, depending on geographic levels chosen, and does minor cleaning, filtering, and aggregation. Note that the underlying tidycensus::get_acs()
requires a Census API key. As is the case with other tidycensus
functions, multi_geo_acs
assumes this key is stored as CENSUS_API_KEY
in your .Renviron
. See tidycensus::census_api_key()
for installation.
A tibble with GEOID, name, variable code, estimate, moe, geography level, state, and year, as applicable, for the chosen ACS table.
tidycensus::census_api_key()
, tidycensus::get_acs()
## Not run:
multi_geo_acs("B01003", 2019,
towns = "all",
regions = list(inner_ring = c("Hamden", "East Haven", "West Haven")),
counties = "New Haven County",
tracts = unique(new_haven_tracts$geoid))
multi_geo_acs("B01003", 2018,
towns = "Bridgeport",
counties = "Fairfield County",
neighborhoods = bridgeport_tracts
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.