FIPS Codes in R: Using tidycensus and tigris
The tidycensus and tigris packages make FIPS-based Census data analysis accessible in R. Here's how to use them effectively.
R users working with US Census data have two excellent packages that handle FIPS geography natively: tidycensus for tabular demographic data and tigris for spatial shapefiles. Both are built around FIPS codes as the primary geographic identifier, which makes them natural tools for any analysis that combines statistical and spatial data.
In tidycensus, you specify geography using state and county FIPS codes or names: get_acs(geography = "county", state = "WA", county = "053", variables = "B01003_001") retrieves ACS population estimates for King County (53033). The package accepts either numeric FIPS codes or state/county names — it handles the lookup internally. For all counties in a state: get_acs(geography = "county", state = "53", variables = "B01003_001").
The tigris package downloads Census TIGER/Line shapefiles as sf objects with GEOID columns that match county FIPS codes. counties(state = "WA") returns a simple features data frame with a GEOID column containing 5-digit FIPS codes for all 39 Washington counties. Joining tidycensus tabular output to tigris spatial data is a single left_join(geometry, data, by = "GEOID").
One common R-specific gotcha: R's default behavior is to convert character vectors with leading zeros to factors or numerics. When reading external CSV files with FIPS codes, use read_csv(col_types = cols(fips = col_character())). The tidycensus package always returns GEOID as a character column, which is the correct behavior. For reference while building your analysis, the state FIPS list and county FIPS guide are useful companions.
More Articles
County FIPS Codes: How 5-Digit Codes Work
County FIPS codes are the workhorses of US geographic data. Understanding their structure unlocks every major federal dataset.
Nov 19, 2025
CDC WONDER and FIPS Codes: Health Data by Geography
The CDC WONDER database is one of the most comprehensive sources of county-level health and mortality data. Here's how it uses FIPS codes.
Mar 31, 2026
HMDA Mortgage Data: Geographic Analysis with FIPS Codes
The Home Mortgage Disclosure Act dataset is one of the most granular public records of mortgage lending in the US. FIPS codes are the key to geographic analysis.
Feb 19, 2026