Created
August 28, 2018 13:22
-
-
Save walkerke/120d972bc301559cb504cdb708d02a3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidycensus) | |
library(tidyverse) | |
library(gganimate) | |
williams <- get_estimates(geography = "county", | |
product = "characteristics", | |
breakdown = c("AGEGROUP", "SEX"), | |
breakdown_labels = TRUE, | |
state = "ND", | |
county = "Williams", | |
time_series = TRUE) %>% | |
filter(str_detect(AGEGROUP, "^Age"), | |
SEX != "Both sexes", | |
!DATE %in% 1:2) %>% | |
mutate(value = ifelse(SEX == "Male", -value, value), | |
year = DATE + 2007) | |
g <- ggplot(williams, aes(x = AGEGROUP, y = value, fill = SEX)) + | |
geom_bar(stat = "identity", width = 1) + | |
theme_minimal(base_family = "Roboto", base_size = 16) + | |
scale_y_continuous(labels = function(y) abs(y)) + | |
scale_x_discrete(labels = function(x) gsub("Age | years", "", x)) + | |
scale_fill_manual(values = c("darkred", "navy")) + | |
coord_flip() + | |
labs(x = "", | |
y = "US Census Bureau population estimate", | |
title = "Estimated population structure, {round(frame_time, 0)}", | |
subtitle = "Williams County, North Dakota", | |
fill = "", | |
caption = "@kyle_e_walker | tidycensus R package") + | |
transition_time(year) + | |
ease_aes("cubic-in-out") | |
ani <- animate(g, height = 500, width = 625) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment