Session 3 - Census Data in R

Using tidycensus to get data from the US Census

October 8, 2021


This is an overview of the October 8th session of LBJ Data Studio. Matt Worthington led today’s session and Ethan supported participants for the duration of the session.

LBJ Studio Dates + Formats

Below are the dates and formats of the session. Our original plan was to eventually hold these in-person, but they will be held on zoom for the first few sessions. The session referenced on this page is highlighted in bold.

  • Zoom Session: Sep 10, 2021 at Noon
  • Zoom Session: Sep 24, 2021 at Noon
  • Zoom Session: Oct 08, 2021 at Noon
  • In-person: Oct 22, 2021 at Noon in Room 3.124 at the LBJ School
  • TBD: Nov 5, 2021 at Noon
  • TBD: Nov 19, 2021 at Noon
  • TBD: Dec 3, 2021 at Noon

What’s Covered In This Session

For this session, we covered the following skills and competencies with a slide deck and a half-hour live coding session.

  • Navigating Rstudio
  • Useful keyboard shortcuts
  • Reproducible analysis workflows using R Markdown
  • Using tidycensus to collect flat and spatial data from the US Census
    • load_variables() function overview
    • get_acs() function overview
  • Revisiting ggplot2

Session Materials

Github Materials

Below is a link to the materials developed during the live coding portion of the session. Participants followed along as we created the materials from scratch. To download the materials, you’ll need to visit Github and download from there (see screenshot below). Once downloaded, place the files in a location on your computer (example: the desktop or documents folder).

Note for Windows users: will want to make sure to extract the downloaded zip before working with the materials.

Downloading Github Materials

Reference Materials

Below is a link to learning more about Kyle Walker’s tidycensus package and other resources that can help you as you explore the world of pulling public data from APIs in R. These won’t cover everything you’ll want to know, nor will every part of it resonate with you, but it will help you in at least some regard. In any event, these are all great resources and many come highly recommended by folks across the world of R:

  • tidycensus documentation This is the documentation for the tidycensus package. It contains all the information about each function available in tidycensus, as well as articles that serve as tutorials on how to utilize core features of tidycensus.
  • The Session Slides Generally speaking, you shouldn’t expect to remember everything you code or write. Referencing back to materials you’ve already viewed or read is very common when coding. Over time, certain things will get easier to remember, but having slides like these helps in a pinch.
  • #rstats hashtag on Twitter People share a ton of great material for R users of every skill level on Twitter. If you’re looking for inspiration and want to see what code people used to make a specific chart, this is the spot to do it. For additional R resources outside of ggplot2, use the #rstats.
  • #tidycensus hashtag on Twitter Similar to the #rstats hashtag, you can often search for the name of an R package on twitter and find a lot of great tutorials, demos, or code-thrus that may help with a project you’re creating. This link provides a ton of great demonstrations and resources specifically focused on tidycensus.
  • Analyzing US Census Data: Methods, Maps, and Models in R This book is hot off the press! Written by the author of tidycensus, this book not only covers working with census data in R, but it’s also a fantastic collection of information to make sense of various products developed by the US Census that are often located in disparate places around the internet.

Resources to Compliment This Workshop

Below are some resources that will help you replicate the live coding demo we produced in the session.

Other Noteworthy API Packages

  • censusapi: Non-spatial accessor to all of Census API data.
  • ipumsr: IPUMS provides census and global survey data.
  • blscrapeR: Bureau of Labor Statistics Data
  • fredr:Federal Reserve of Economic Data
  • idbr: Interface to the US Census Bureau International Data Base
  • cancensus: Candian Census Data
  • mxmaps and inegiR: Tools for working with data in Mexico.
  • rKenyaCensus: Kenyan Data
  • geobr: Brazilian Data
  • nomisr: Data from the UK
  • WDI: World Bank Data


Photo in the preview of this page by Enayet Raheem on Unsplash