knitr::opts_chunk$set( fig.path = "man/figures/README-", message = FALSE, warning = FALSE, collapse = TRUE, comment = "#>", out.width = "100%", fig.showtext = TRUE, dev = "png", dpi = 300 )
camiller
is a set of convenience functions, functions for working with ACS data via tidycensus
, and a ggplot
theme.
Install from GitHub with:
# install.packages("devtools") devtools::install_github("camille-s/camiller")
This is a basic example of two of the major functions in this package, add_grps
and calc_shares
:
library(dplyr) library(camiller) edu_list <- list(ages25plus = 1, less_than_high_school = 2:16, high_school = 17:18, some_college_or_aa = 19:21, bachelors_plus = 22:25) edu_rates <- edu_detail %>% dplyr::group_by(name) %>% add_grps(edu_list, group = variable, moe = moe) %>% calc_shares(group = variable, denom = "ages25plus", moe = moe) edu_rates
Plus this ggplot
theme.
library(ggplot2) library(forcats) library(showtext) font_add_google("Archivo Narrow", "archivo") showtext_auto() showtext_opts(dpi = 300) edu_rates %>% ungroup() %>% filter(!is.na(share)) %>% arrange(variable, share) %>% mutate(name = as_factor(name) %>% fct_rev()) %>% mutate(variable = fct_rev(variable) %>% fct_relabel(clean_titles) %>% fct_recode("Bachelor's or higher" = "Bachelors plus", "Some college or Associate's" = "Some college or aa")) %>% ggplot(aes(x = name, y = share, fill = variable)) + geom_col(position = "fill", width = 0.8, alpha = 0.9) + scale_y_continuous(labels = scales::percent) + scale_fill_manual(values = c("#FBB4B9", "#F768A1", "#C51B8A", "#7A0177")) + labs(x = NULL, y = "Share of adults 25+", fill = "Education level", title = "Educational attainment level by town", subtitle = "Among adults ages 25 or over, 2016", caption = "Source: US Census Bureau ACS 2016 5-year estimates") + theme_din(base_family = "archivo")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.