knitr::opts_chunk$set( cache = TRUE, collapse = TRUE, comment = "#>", fig.path = "README-files/" )
The R package {fips} makes it easier to merge geographic identifiers such as state FIPS, county FIPS, urban-rural codes, BEA region codes, and census region and division codes.
For an overview of regions of the United States, see the wiki page for List of regions of the United States.
The following datasets are available:
fips::fips
, fips::state
, and fips::lower48
:
fips::fips
contains 50 states, the District of Columbia, and the Outlying Areas of the United States.fips::state
contains 50 states and the District of Columbia.fips::lower48
contains the 48 Contiguous Continental States and the District of Columbia.fips::county
, fips::county_ipums_usa
fips::nchs_urc
:
fips::bea_region
:
fips::census_region_division
:
I might add other crosswalks for OMB standard federal regions, federal reserve districts, courts of appeals circuits, and Agricultural Research Service regions.
Similar implementation in Stata:
Similar R packages:
You can install the development version of {fips} from Github with:
# install.packages("remotes") remotes::install_github("jjchern/fips")
Or install the most recent released version of {fips} from Github with:
remotes::install_github("jjchern/fips@v0.0.5")
library(tidyverse) fips::state # fips::fips includes FIPS code for other outlying areas fips::fips fips::fips %>% tail(10) # fips::lower48 includes the 48 continental states and DC fips::lower48
fips::county
fips::county_ipums_usa %>% select(state, countyfip, county_name, `2000 5% & 1% unwt, acs 2005`, `acs 2006-2011`, `2010 10%, acs 2012-onward`) %>% na.omit() %>% select(state, countyfip, county_name) %>% knitr::kable()
fips::census_region_division
right_join(usmapdata::state, fips::census_region_division, by = c("id" = "fips")) %>% haven::as_factor() -> census_region_division ggplot() + geom_map(data = census_region_division, map = census_region_division, aes(x = long, y = lat, map_id = id, fill = region_name), colour = alpha("white", 0.1), size = 0.2) + geom_map(data = usmapdata::state, map = usmapdata::state, aes(x = long, y = lat, map_id = id), colour = alpha("white", 0.75), fill = "NA") + coord_map("albers", lat0 = 30, lat1 = 40) + viridis::scale_fill_viridis(option = "C", discrete = TRUE) + ggtitle("Component State for Census Regions") + ggthemes::theme_map() + theme(legend.position = c(.82, .4), legend.title = element_blank(), plot.title = element_text(hjust = 0.5))
ggplot() + geom_map(data = census_region_division, map = census_region_division, aes(x = long, y = lat, map_id = id, fill = division_name), colour = alpha("white", 0.1), size = 0.2) + geom_map(data = usmapdata::state, map = usmapdata::state, aes(x = long, y = lat, map_id = id), colour = alpha("white", 0.75), fill = "NA") + coord_map("albers", lat0 = 30, lat1 = 40) + viridis::scale_fill_viridis(option = "C", discrete = TRUE) + ggtitle("Component State for Census Divisions") + ggthemes::theme_map() + theme(legend.position = c(.82, .2), legend.title = element_blank(), plot.title = element_text(hjust = 0.5))
fips::bea_region
right_join(usmapdata::state, fips::bea_region, by = c("id" = "fips")) %>% haven::as_factor() -> bea_region ggplot() + geom_map(data = bea_region, map = bea_region, aes(x = long, y = lat, map_id = id, fill = short_region_name), colour = alpha("white", 0.1), size = 0.2) + geom_map(data = usmapdata::state, map = usmapdata::state, aes(x = long, y = lat, map_id = id), colour = alpha("white", 0.75), fill = "NA") + coord_map("albers", lat0 = 30, lat1 = 40) + viridis::scale_fill_viridis(option = "C", discrete = TRUE) + ggtitle("Component State for BEA Regions") + ggthemes::theme_map() + theme(legend.position = c(.82, .3), legend.title=element_blank(), plot.title = element_text(hjust = 0.5))
fips::nchs_urc
right_join(usmapdata::county, fips::nchs_urc, by = c("id" = "fips")) %>% haven::as_factor() -> nchs_urc ggplot() + geom_map(data = nchs_urc, map = nchs_urc, aes(x = long, y = lat, map_id = id, fill = code2013), colour = alpha("white", 0.1), size = 0.2) + geom_map(data = usmapdata::state, map = usmapdata::state, aes(x = long, y = lat, map_id = id), colour = alpha("white", 0.75), fill = "NA") + coord_map("albers", lat0 = 30, lat1 = 40) + viridis::scale_fill_viridis(option = "B", discrete = TRUE) + ggtitle("2013 NCHS Urban-Rural Classification Scheme for Counties") + ggthemes::theme_map() + theme(legend.position = c(.82, .3), legend.title=element_blank(), plot.title = element_text(hjust = 0.5))
ggplot() + geom_map(data = nchs_urc, map = nchs_urc, aes(x = long, y = lat, map_id = id, fill = code2006), colour = alpha("white", 0.1), size = 0.2) + geom_map(data = usmapdata::state, map = usmapdata::state, aes(x = long, y = lat, map_id = id), colour = alpha("white", 0.75), fill = "NA") + coord_map("albers", lat0 = 30, lat1 = 40) + viridis::scale_fill_viridis(option = "A", discrete = TRUE) + ggtitle("2006 NCHS Urban-Rural Classification Scheme for Counties") + ggthemes::theme_map() + theme(legend.position = c(.82, .3), legend.title=element_blank(), plot.title = element_text(hjust = 0.5))
nchs_urc %>% filter(!is.na(code1990)) %>% ggplot() + geom_map(map = nchs_urc, aes(x = long, y = lat, map_id = id, fill = code1990), colour = alpha("white", 0.1), size = 0.2) + geom_map(data = usmapdata::state, map = usmapdata::state, aes(x = long, y = lat, map_id = id), colour = alpha("white", 0.75), fill = "NA") + coord_map("albers", lat0 = 30, lat1 = 40) + viridis::scale_fill_viridis(option = "C", discrete = TRUE) + ggtitle("1990 NCHS Urban-Rural Classification Scheme for Counties") + ggthemes::theme_map() + theme(legend.position = c(.82, .3), legend.title=element_blank(), plot.title = element_text(hjust = 0.5))
The {fips} package are available under the Creative Commons CC0 1.0 License, so feel free (literally) to use it for any purpose without any attribution.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.