knitr::opts_chunk$set(echo = TRUE)
The psrccensus
package allows R users at PSRC to download, summarize, and visualize Census, ACS, and PUMS data on common PSRC Census geographies.
Some of the Census, ACS, and PUMS data can be found in our Elmer database: see the internal wiki for more information.
You would want to use psrccensus
as opposed to Elmer if: you are working in R, you need a table not in Elmer, and/or you would like a formatted table or map to be produced.
The three most important functions are:
get_decennial_recs()
"functions for getting Census tables")
get_psrc_pums()
"function for getting Public Use Microsample Data")
To use psrccensus
, you first will need to get an API key.
A key is required to access the Census API. If you haven't done this before, you should set your Census API Key as an environment variable or store it in your .Renviron file.
Obtain a Census API key here: https://api.census.gov/data/key_signup.html.
There are two methods to set your key:
Once you run Sys.setenv()
on the Census API Key you will only need to run Sys.getenv()
.
r
library(psrccensus)
#Sys.setenv(CENSUS_API_KEY = 'PUT YOUR KEY HERE')
Sys.getenv("CENSUS_API_KEY")
An alternative method is to install the key in your .Renviron File for repeated use. This is done via the tidycensus
package. The benefit is that you would not have to call Sys.getenv()
everytime you run your script or other scripts using psrccensus
or tidycensus
.
```r
tidycensus::census_api_key('your api key', install = TRUE) ```
Next you need to decide what tables you would like to download and summarize. This is the hardest part because you have to find the correct table code, decide on geography, and which years.
One helpful website for finding the tables on a topic from the ACS and Census is: https://censusreporter.org/
Many of our frequently used Census/ACS/PUMS tables are nicely described in our wiki. Note that Census table names in Elmer are given a two character code such as "H2". In psrccensus
, to be consistent with the tidycensus
package, codes must be padded with zeroes so that "H2" becomes "H002".
You can also search the API variable lists from ACS and Census.
2020 Census: https://www.census.gov/data/developers/data-sets/decennial-census.html
2019 ACS 1-year: https://api.census.gov/data/2019/acs/acs1/variables.html
2015-2019 ACS 5-year: https://api.census.gov/data/2019/acs/acs5/variables.html
2010 Census: https://www.census.gov/data/developers/data-sets/decennial-census.html
The 2020 Census data differs from the 2010 Census datasets. Changes to 2020 Census datasets: https://www2.census.gov/programs-surveys/decennial/2020/program-management/2010_20_data_product_release_dates.pdf
Generally, ACS 1-year data are available down for geographies with populations of 65,000 or more, so you can easily get 1-year data for counties or the region, for example. Once you want to go down to the tract-level, 5-year ACS data is more appropriate. Decennial Census data is available down to the block level.
Functions currently in psrccensus
will only return data in Washington State at the county, tract, MSA, and place levels. To access other geographies, consider using tidycensus
directly.
View the Get Data vignette (under Articles) on how to use the primary functions.
View the Calculate PUMS Summaries vignette (under Articles) on learn how to create aggregations of PUMS data for the region.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.