Created
October 16, 2020 13:45
-
-
Save farach/2e73a7d8961d4ab41fe5cd0d0a6f9479 to your computer and use it in GitHub Desktop.
AFS DSS_1
This file contains hidden or 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
# install.packages("pacman") | |
pacman::p_load("tidyverse", "RColorBrewer", "janitor") | |
nitrd_fill <- read.csv("https://www.nitrd.gov/data/NITRD_Budget_Tables.csv") %>% | |
janitor::clean_names(.) %>% | |
mutate( | |
budget = as.numeric(str_remove(as.character(budget), ",")), | |
fy = as.numeric(fy) | |
) %>% | |
group_by(fy, pca) %>% | |
summarize(budget = sum(budget, na.rm = TRUE)) %>% | |
filter(pca != "All PCAs") %>% | |
pivot_wider(names_from = pca, values_from = budget) %>% | |
mutate(across(everything(), ~replace_na(.x, 0))) %>% | |
pivot_longer(cols = -fy, names_to = "pca", values_to = "budget") %>% | |
mutate(total = sum(budget, na.rm = TRUE), | |
percentage = budget/sum(budget, na.rm = TRUE)) | |
color <- grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = T)] | |
n <- length(unique(nitrd_fill$pca)) | |
ggplot(nitrd_fill) + | |
geom_area(aes(fy, percentage, fill = pca), | |
alpha = 0.5, size = 1, color = "black") + | |
labs( | |
title = "NITDR Budget", | |
x = "Fiscal year", | |
y = "% of budget", | |
fill = "Program \ncomponent \nareas:", | |
caption = "source: www.nitrd.gov" | |
) + | |
theme_minimal() + | |
theme(axis.title.x = element_text(hjust = .95, size = 9), | |
axis.title.y = element_text(hjust = 1, size = 9), | |
plot.title = element_text(hjust = 0.5, size = 20), | |
legend.position = "bottom" | |
) + | |
scale_y_continuous(labels = scales::percent) + | |
scale_fill_discrete(type = sample(color, n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment