Obtain and set your Census API key
tidycensus
is an R package designed to return data from the US Census Bureau ready for use within the Tidyverse.
To acquire data from the US Census Bureau using the tidycensus R package, you must first acquire and set a Census API key. After obtaining your key, you can install it for future use with the census_api_key()
function in tidycensus.
This exercise uses a fake API key for purposes of illustration.
This is a part of the course
“Analyzing US Census Data in R”
Exercise instructions
- Load the
tidycensus
package into your DataCamp R session. - Set the Census API key with
census_api_key()
. - Check your API key with
Sys.getenv()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load the tidycensus package into your R session
library(___)
# Define your Census API key and set it with census_api_key()
api_key <- "rw6pozt48ur2ugc8kg69x5phdrtnuhb2cb1subd6"
census_api_key(___)
# Check your API key
___("CENSUS_API_KEY")
This exercise is part of the course
Analyzing US Census Data in R
Learn to rapidly visualize and explore demographic data from the United States Census Bureau using tidyverse tools.
In this chapter, students will learn the basics of working with Census data in R with tidycensus. They will acquire data using tidycensus functions, search for data, and make a basic plot.
Exercise 1: Census data in R: an overviewExercise 2: Obtain and set your Census API keyExercise 3: Getting Census data with tidycensusExercise 4: Basic tidycensus functionalityExercise 5: Understanding tidycensus optionsExercise 6: Tidy and wide data in tidycensusExercise 7: Searching for data with tidycensusExercise 8: Loading variables in tidycensusExercise 9: Exploring variables with tidyverse toolsExercise 10: Visualizing Census data with ggplot2Exercise 11: Comparing geographies with ggplot2 visualizationsExercise 12: Customizing ggplot2 visualizations of ACS dataWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.