Enyo/Visuals.r
2026-03-17 16:49:20 -06:00

63 lines
4.7 KiB
R

library(tidyverse)
#install.packages("paletteer")
library(scales)
library(paletteer)
DATA_DIR <- 'Results/REMI_Output/'
OUTPUT_DIR <- './Results/Figures/'
dir.create(OUTPUT_DIR,recursive=TRUE,showWarnings=FALSE)
######################Employments
EMPLOY <- read_csv(paste0(DATA_DIR,"Direct, Indirect, and Induced -Employment.csv" ),skip=5) %>% pivot_longer(c(-Category,-Units),names_to="Year") %>% mutate(value=parse_number(value),Year=parse_number(Year))
EMPLOY_NUM <- EMPLOY %>% filter(Units=='Individuals (Jobs)') %>% select(-Units,Employment=value) %>% filter(Year>=2028)
EMPLOY_NUM <- rbind(EMPLOY_NUM %>% filter(!(Year %in% c(2028,2029))) ,EMPLOY_NUM %>% filter(Year==2028) %>% mutate(Year=2029.74),EMPLOY_NUM %>% filter(Year==2029) %>% mutate(Year=2029.75))
EMPLOY_NUM$Category <- gsub(" Employment","",EMPLOY_NUM$Category)
EMPLOY_NUM$Category <- factor(EMPLOY_NUM$Category,levels=rev(c("Direct","Indirect","Induced","Total")))
COLORS <- rev(paletteer_d("fishualize::Alosa_fallax",n=4,direction=1)[-2])
MAX_VAL <- round(max(EMPLOY_NUM$Employment))
COOL_DOWN <- as.numeric(EMPLOY_NUM[5,3])
df <- data.frame(Year=c(2032.5,2034.25,2046,2059.8),Employment=c(MAX_VAL,COOL_DOWN,791+20,743+20),text=c("Peak of 2,530","Stablized at 961","Midpoint of 791","Ends at 743"))
JOB_PLOT <- ggplot(EMPLOY_NUM %>% filter(Category!="Total"),aes(x=Year,y=Employment))+geom_area(position = "stack",aes(fill=Category,group=Category))+theme_bw()+scale_x_continuous(breaks=c(2028,seq(2025,2060,by=5)))+scale_fill_manual(values=COLORS)+geom_line(data=EMPLOY_NUM %>% filter(Category=="Total"),size=1)+geom_text(data=df,aes(label = text), vjust = "inward", hjust = "inward")+theme(legend.position = "top")
png(paste0(OUTPUT_DIR,"Job_plot.png" ) , units = "in", width = 10, height = 8, res = 600)
JOB_PLOT
dev.off()
#JOB_PLOT
###################Output graph
OUTPUT <- read_csv(paste0(DATA_DIR,"Direct, Indirect, and Induced -Output.csv" ),skip=5) %>% pivot_longer(c(-Category,-Units),names_to="Year") %>% mutate(value=parse_number(value),Year=parse_number(Year))
OUTPUT_NUM <- OUTPUT %>% filter(Units=='Thousands of Fixed (2025) Dollars') %>% select(-Units,Output=value) %>% filter(Year>=2028) %>% mutate(Output=Output/1000)
OUTPUT_NUM <- rbind(OUTPUT_NUM %>% filter(!(Year %in% c(2028,2029))) ,OUTPUT_NUM %>% filter(Year==2028) %>% mutate(Year=2029.74),OUTPUT_NUM %>% filter(Year==2029) %>% mutate(Year=2029.75))
OUTPUT_NUM %>% filter(Year==2033)
OUTPUT_NUM$Category <- gsub(" Output","",OUTPUT_NUM$Category)
OUTPUT_NUM$Category <- factor(OUTPUT_NUM$Category,levels=rev(c("Direct","Indirect","Induced","Total")))
#COLORS <- rev(paletteer_d("fishualize::Alosa_fallax",n=4,direction=1)[-2])
MAX_VAL <- round(max(OUTPUT_NUM$Output))
COOL_DOWN <- as.numeric(OUTPUT_NUM[5,3])
#COOL_DOWN
#MAX_VAL
#OUTPUT_NUM %>% filter(Year==2060)
df <- data.frame(Year=c(2032.5,2034.25,2059.8),Output=c(MAX_VAL,COOL_DOWN,337),text=c("Peak of $658 Million","Stablized at $273 Million ","Ends at $337 Million"))
#OUTPUT_PLOT <-
OUTPUT_NUM %>% filter(Year==2033)
OUTPUT_PLOT <- ggplot(OUTPUT_NUM %>% filter(Category!="Total"),aes(x=Year,y=Output))+geom_area(position = "stack",aes(fill=Category,group=Category))+theme_bw()+scale_x_continuous(breaks=c(2028,seq(2025,2060,by=5)))+scale_fill_manual(values=COLORS)+geom_line(data=OUTPUT_NUM %>% filter(Category=="Total"),size=1)
#+geom_text(data=df,aes(label = text), vjust = "inward", hjust = "inward")+theme(legend.position = "top")
png(paste0(OUTPUT_DIR,"Output_plot.png"), units = "in", width = 10, height = 8, res = 600)
OUTPUT_PLOT
dev.off()
###################
INDUSTRY_JOBS <- read_csv(paste0(DATA_DIR,'Employment- By Industry - Employment by Industry.csv'),skip=5) %>% pivot_longer(c(-Industry,-Units),names_to="Year") %>% mutate(Jobs=parse_number(value),Year=parse_number(Year)) %>% select(-value) %>% filter(Industry!='All Industries') %>% select(-Units) %>% filter(Year>=2029)
INDUSTRY_JOBS <- INDUSTRY_JOBS %>% group_by(Year) %>% mutate(Rank=rank(-Jobs)) %>% mutate(Rank=ifelse(Rank>10,11,Rank),Industry=ifelse(Rank==11,"Other",Industry)) %>% group_by(Year,Industry,Rank) %>% summarize(Jobs=sum(Jobs)) %>% ungroup(Industry,Rank) %>% arrange(Year,Rank)
ORDER <- c(INDUSTRY_JOBS %>% filter(Industry!='Other') %>% group_by(Industry) %>% summarize(MEAN=mean(Jobs)) %>% arrange(desc(MEAN)) %>% pull(Industry) %>% unique,"Other")
INDUSTRY_JOBS$Industry <- factor(INDUSTRY_JOBS$Industry,levels=ORDER)
ggplot(INDUSTRY_JOBS ,aes(x=Year,y=Jobs,fill=Industry))+geom_bar(stat='identity')+ paletteer::scale_fill_paletteer_d("colorBlindness::Blue2DarkRed18Steps")
ggplot(INDUSTRY_JOBS %>% filter(Year %in% c(2032,2045)),aes(x=as.factor(Year),y=Jobs,fill=Industry))+geom_bar(stat='identity')+ paletteer::scale_fill_paletteer_d("colorBlindness::Blue2DarkRed18Steps")