knitr::opts_chunk$set( cache = TRUE, collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
county.pop
The package stores U.S. annual county-level population estimates (1969-2016) from SEER. The dataset is unbalanced: certain counties do not have population estimates for all the years.
# install.packages("devtools") devtools::install_github("jjchern/county.pop@v0.0.4") # To uninstall the package, use: # remove.packages("county.pop")
library(tibble) county.pop::pop_since_1969 county.pop::pop_since_1969_adjusted county.pop::pop_since_1990 county.pop::pop_since_1990_adjusted
The population counts are usually based on July 1 populations. The two adjusted versions take into account the changes in population due to hurricanes Katrina and Rita.
All four data sets provide total population counts at the county-year level, as well as population counts by
pop_since_1969
: black, other, whitepop_since_1990
: Hispanic, non-Hispanic black, non-Hispanic other, and non-Hispanic whiteFor example, Broomfield County, Colorado (08014) are created on November 15, 2001 (https://www.census.gov/geo/reference/county-changes.html).
library(tidyverse) county.pop::pop_since_1990 %>% filter(county_fips == "08014") %>% distinct(year)
county.pop::pop_since_1990 %>% group_by(usps, year) %>% summarise(state_pop = sum(pop))
county.pop::pop_since_1969 %>% select(state, year, pop, age_65_85p) %>% group_by(state, year) %>% summarise_all(sum) %>% mutate(sh_age_65p = age_65_85p / pop) %>% left_join(fips::bea_region) %>% ungroup() -> df df %>% ggplot(aes(x = year, y = state, fill = sh_age_65p)) + geom_tile() + scale_x_continuous(breaks = seq(1969, 2016, 5)) + facet_grid(short_region_name~., scales = "free_y", space = "free_y") + viridis::scale_fill_viridis(labels=scales::percent) + labs(x = NULL, y = NULL, title = "Aging in the United States", fill = "Ages 65+") + theme_bw() + theme(strip.text = element_text(size = 9)) + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.