install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
install.packages("dplyr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
install.packages("ggplot2")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
install.packages("reshape2")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
install.packages("ggpubr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
install.packages("scales")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(ggplot2)
library(reshape2)
## 
## Attaching package: 'reshape2'
## 
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(ggpubr)
library(scales)
## 
## Attaching package: 'scales'
## 
## The following object is masked from 'package:purrr':
## 
##     discard
## 
## The following object is masked from 'package:readr':
## 
##     col_factor
df <- read.csv("Agency Appropriations by Year.csv")
df <- df %>%
  rename("2018" = "FY.2018.Appropriation", "2019" = "FY.2019.Appropriation", "2020" = "FY.2020.Appropriation", "2021" = "FY.2021.Appropriation", "2022" = "FY.2022.Appropriation")
df <- df[(1:15), (1:6)]
df_pie <- melt(df, id="Agency", variable.name = "Year", value.name = "Appropriation")
df <- as.data.frame(t(df))
colnames(df) <- df[1, ]
df <- df[-1, ]
df <- cbind(Year = rownames(df), df)
rownames(df) <- 1:nrow(df)
sapply(df, class)
##                                          Year 
##                                   "character" 
##                         Agency Accountability 
##                                   "character" 
##                                   Agriculture 
##                                   "character" 
##            Commerce and Workforce Development 
##                                   "character" 
##     Digital Transformation and Administration 
##                                   "character" 
##                        Energy and Environment 
##                                   "character" 
##                      Health and Mental Health 
##                                   "character" 
## Human Services and Early Childhood Incentives 
##                                   "character" 
##                                 Public Safety 
##                                   "character" 
##                        Science and Technology 
##                                   "character" 
##              Secretary of State and Education 
##                                   "character" 
##                          Tourism and Branding 
##                                   "character" 
##                                Transportation 
##                                   "character" 
##                 Veterans Affairs and Military 
##                                   "character" 
##                                   Legislature 
##                                   "character" 
##                                     Judiciary 
##                                   "character"
df[, 2:16] <- sapply(df[, 2:16], function(x) as.numeric(gsub(",", "", x)))
sapply(df, class)
##                                          Year 
##                                   "character" 
##                         Agency Accountability 
##                                     "numeric" 
##                                   Agriculture 
##                                     "numeric" 
##            Commerce and Workforce Development 
##                                     "numeric" 
##     Digital Transformation and Administration 
##                                     "numeric" 
##                        Energy and Environment 
##                                     "numeric" 
##                      Health and Mental Health 
##                                     "numeric" 
## Human Services and Early Childhood Incentives 
##                                     "numeric" 
##                                 Public Safety 
##                                     "numeric" 
##                        Science and Technology 
##                                     "numeric" 
##              Secretary of State and Education 
##                                     "numeric" 
##                          Tourism and Branding 
##                                     "numeric" 
##                                Transportation 
##                                     "numeric" 
##                 Veterans Affairs and Military 
##                                     "numeric" 
##                                   Legislature 
##                                     "numeric" 
##                                     Judiciary 
##                                     "numeric"
AA <- ggplot(df, aes(x=Year, y=`Agency Accountability`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Agency Accountability") +
  theme(plot.title = element_text(size = 10, face = "bold"))

AA

Ag <- ggplot(df, aes(x=Year, y=`Agriculture`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Agriculture") +
  theme(plot.title = element_text(size = 10, face = "bold"))

Ag

CWD <- ggplot(df, aes(x=Year, y=`Commerce and Workforce Development`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Commerce and Workforce Development") +
  theme(plot.title = element_text(size = 6, face = "bold"))

CWD

DTA <- ggplot(df, aes(x=Year, y=`Digital Transformation and Administration`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Digital Transformation and Administration") +
  theme(plot.title = element_text(size = 5, face = "bold"))

DTA

EE <- ggplot(df, aes(x=Year, y=`Energy and Environment`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Energy and Environment") +
  theme(plot.title = element_text(size = 10, face = "bold"))

EE

HMH <- ggplot(df, aes(x=Year, y=`Health and Mental Health`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Health and Mental Health") +
  theme(plot.title = element_text(size = 8, face = "bold"))

HMH

HSECI <- ggplot(df, aes(x=Year, y=`Human Services and Early Childhood Incentives`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Human Services and Early Childhood Incentives") +
  theme(plot.title = element_text(size = 5, face = "bold"))

HSECI

PS <- ggplot(df, aes(x=Year, y=`Public Safety`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Public Safety") +
  theme(plot.title = element_text(size = 10, face = "bold"))

PS

ST <- ggplot(df, aes(x=Year, y=`Science and Technology`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Science and Technology") +
  theme(plot.title = element_text(size = 9, face = "bold"))

ST

SSE <- ggplot(df, aes(x=Year, y=`Secretary of State and Education`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Secretary of State and Education") +
  theme(plot.title = element_text(size = 6, face = "bold"))

SSE

TB <- ggplot(df, aes(x=Year, y=`Tourism and Branding`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Tourism and Branding") +
  theme(plot.title = element_text(size = 10, face = "bold"))

TB

Tr <- ggplot(df, aes(x=Year, y=`Transportation`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Transportation") +
  theme(plot.title = element_text(size = 10, face = "bold"))

Tr

VAM <- ggplot(df, aes(x=Year, y=`Veterans Affairs and Military`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Veterans Affairs and Military") +
  theme(plot.title = element_text(size = 7, face = "bold"))

VAM

Lg <- ggplot(df, aes(x=Year, y=`Legislature`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Legislature") +
  theme(plot.title = element_text(size = 10, face = "bold"))

Lg

Ju <- ggplot(df, aes(x=Year, y=`Judiciary`, group=1)) +
  geom_line() +
  theme_minimal() +
  ylab("Appropriation") +
  ggtitle("Judiciary") +
  theme(plot.title = element_text(size = 10, face = "bold"))

Ju

ggarrange(AA, Ag, CWD, DTA, EE, HMH, HSECI, PS, ST, SSE, TB, Tr, VAM, Lg, Ju)

df_pie$Appropriation <- gsub(",", "", df_pie$Appropriation)

df_pie$Appropriation <- gsub(".00", "", df_pie$Appropriation)

df_pie$Appropriation <- as.numeric(df_pie$Appropriation)
ggplot(df_pie, aes(x="", y=Appropriation, fill=Agency)) +
  geom_bar(stat="identity", width=1) +
  theme_minimal() +
  facet_grid(.~ Year) +
  xlab("Year") +
  ggtitle("Total State Appropriations by Year") +
  scale_y_continuous(labels=dollar)