Get population data for Kansas City
get_kc_pop.RdDownload population data for Kansas City from the decennial census or the American Community Survey (ACS). Summary levels are place, county, census tract, census block group, census block (decennial census only), and ZIP code tabulation area (ZCTA). Data sets are downloaded from the US Census Bureau using the tidycensus package.
Arguments
- dataset
The data set to download. Passed to the
datasetargument intidycensus::load_variables()and eithersurveyintidycensus::get_acs()orsumfileintidycensus::get_decennial().- geo
The data set geography (summary level).
- year
The data set year.
- vars
The variables to download. Either a vector of variable names or a regular expression pattern.
- var_match
Use
"fixed"to match variable names invarsexactly or"regex"to match them to a regular expression pattern.- geoids
A vector of GEOIDs to filter the output.
- ...
Additional arguments passed to
tidycensus::get_acs()ortidycensus::get_decennial(), such askeyfor the user's census API key.
Details
ACS and census variables can be explored at the Census Reporter website
or by using tidycensus::load_variables() to download variables for a
specific data set.
GEOIDs can be obtained from US Census Bureau shapefiles or from the data set
geoid in this package.
By default, state = 29 is included in the call to the relevant tidycensus
function.
Additional resources
Census Reporter (ACS tables and variables reference)
Examples
if (FALSE) { # \dontrun{
# Download place-level data from the 2024 1-year ACS
acs1_2024_place <- get_kc_pop(
dataset = "acs1",
geo = "place",
year = 2024,
vars = "^B01",
var_match = "regex",
geoids = geoid$place,
key = keyring::key_get("census-api-key")
)
# Download ZCTA-level data from the 2023 5-year ACS
acs5_2023_zcta <- get_kc_pop(
dataset = "acs5",
geo = "zcta",
year = 2023,
vars = "B01001_001",
var_match = "fixed",
geoids = geoid$zcta2020,
key = keyring::key_get("census-api-key")
)
# Download census block-level data from the 2020 census
block <- get_kc_sf(
geo = "block",
year = 2024,
intersect = "city",
geometry = "full"
)
geoid_block <- block$GEOID20
census_2020_block <- get_kc_pop(
dataset = "dhc",
geo = "block",
year = 2020,
vars = "P12_001N",
var_match = "fixed",
geoids = geoid_block,
county = sub("^29", "", geoid$county),
key = keyring::key_get("census-api-key")
)
} # }