From 86c9c7a6fa03668d1a99df7593e0646cde85f8db Mon Sep 17 00:00:00 2001 From: Alex Gebben Work Date: Tue, 24 Mar 2026 15:37:24 -0600 Subject: [PATCH] Made intial figures --- .gitignore | 1 + Visuals.r | 108 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 74 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 5dd16fc..c13cfc2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +Results/Tables_and_Figures/* *.png *.swp diff --git a/Visuals.r b/Visuals.r index a95dd84..83da4ec 100644 --- a/Visuals.r +++ b/Visuals.r @@ -4,7 +4,7 @@ library(tidyverse) library(scales) library(paletteer) DATA_DIR <- 'Results/REMI_Output/' -OUTPUT_DIR <- './Results/Figures/' +OUTPUT_DIR <- './Results/Tables_and_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(Year=parse_number(Year)) @@ -21,7 +21,7 @@ COOL_DOWN <- as.numeric(EMPLOY_NUM[5,3]) #EMPLOY_NUM #EMPLOY_NUM %>% filter(Category=='Total') %>% arrange(Year)%>% print(n=100) df <- data.frame(Year=c(2032.5,2034.25,2040.25,2059.75),Employment=c(MAX_VAL+50,COOL_DOWN,687+20,596+20),text=c("Peak of 2,521","Stabalized at 878" ,"687 in 2040","Ends at 596")) -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(2029,seq(2025,2060,by=2)))+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")+scale_y_continuous(labels = scales::comma,breaks=seq(0,3000,by=250)) +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(2029,seq(2025,2060,by=2)))+scale_fill_manual(values=COLORS)+geom_line(data=EMPLOY_NUM %>% filter(Category=="Total"),linewidth=1)+geom_text(data=df,aes(label = text), vjust = "inward", hjust = "inward")+theme(legend.position = "top")+scale_y_continuous(labels = scales::comma,breaks=seq(0,3000,by=250)) png(paste0(OUTPUT_DIR,"Job_plot.png" ) , units = "in", width = 11, height = 8, res = 600) JOB_PLOT @@ -35,7 +35,12 @@ OUTPUT_NUM <- rbind(OUTPUT_NUM %>% filter(!(Year %in% c(2028,2029))) ,OUTPUT_NU OUTPUT_NUM$Category <- gsub(" Output","",OUTPUT_NUM$Category) OUTPUT_NUM$Category <- factor(OUTPUT_NUM$Category,levels=rev(c("Direct","Indirect","Induced","Total"))) - 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(2029,seq(2025,2060,by=2)))+scale_fill_manual(values=COLORS)+geom_line(data=OUTPUT_NUM%>% filter(Category=="Total"),size=1)+theme(legend.position = "top")+scale_y_continuous(labels = scales::comma,breaks=seq(0,600,by=25))+ylab("Economic Output (Million USD)") + 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(2029,seq(2025,2060,by=2)))+scale_fill_manual(values=COLORS)+geom_line(data=OUTPUT_NUM%>% filter(Category=="Total"),linewidth=1)+theme(legend.position = "top")+scale_y_continuous(labels = scales::comma,breaks=seq(0,600,by=25))+ylab("Economic Output (Million USD)") + +png(paste0(OUTPUT_DIR,"Output_plot.png"), units = "in", width = 10, height = 8, res = 600) + OUTPUT_PLOT +dev.off() + ####GDP and Output @@ -43,33 +48,29 @@ GDP <- read_csv(paste0(DATA_DIR,"Gross Domestic Product - By Region - GDP by Reg GDP <- GDP %>% filter(Region !='All Regions') GDP$Region <- gsub(" County","",GDP$Region) KEY_REGIONS <- GDP %>% group_by(Region) %>% summarize(GDP = median(GDP)) %>% arrange(desc(GDP)) %>% filter(GDP>0) %>% pull(Region) -OTHER_GDP <- GDP %>% filter(!(Region %in% KEY_REGIONS)) %>% group_by(Year) %>% summarize(Region="Other",GDP=sum(GDP)) %>% ungroup +OTHER_GDP <- GDP %>% filter(!(Region %in% KEY_REGIONS)) %>% group_by(Year) %>% summarize(Region="Other Counties",GDP=sum(GDP)) %>% ungroup GDP <- rbind(GDP %>% filter(Region %in% KEY_REGIONS),OTHER_GDP) -GDP$Region <- factor(GDP$Region,levels=rev(c(KEY_REGIONS,"Other"))) +GDP$Region <- factor(GDP$Region,levels=rev(c("Other Counties",KEY_REGIONS))) +GDP <- GDP %>% filter(Year>=2029) -ggplot(GDP %>% filter(Region!='Lincoln'),aes(x=Year,y=GDP,fill=Region))+geom_area(position='stack') -GDP <- read_csv(paste0(DATA_DIR,"Gross Domestic Product - By Region - GDP by Region.csv" ),skip=5) %>% pivot_longer(c(-Region,-Units),names_to="Year",values_to="GDP") %>% mutate(Year=parse_number(Year),GDP=GDP*1000) %>% select(-Units) - - -OUTPUT_NUM$Category <- gsub(" Output","",OUTPUT_NUM$Category) -OUTPUT_NUM$Category <- factor(OUTPUT_NUM$Category,levels=rev(c("Direct","Indirect","Induced","Total"))) - -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) -OUTPUT_PLOT -#+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 +GDP_SUB_REGION_PLOT <- ggplot(GDP %>% filter(Region!='Lincoln'),aes(x=Year,y=GDP,fill=Region))+geom_area(position='stack')+scale_x_continuous(breaks=c(2029,seq(2025,2060,by=2)))+scale_y_continuous(labels = scales::comma,breaks=seq(0,30,by=1))+theme(legend.position = "top")+theme_bw()+ylab("GDP (Million USD)")+scale_fill_manual(values=paletteer_d("PNWColors::Shuksan2")) +png(paste0(OUTPUT_DIR,"GDP_Other_Counties.png"), units = "in", width = 10, height = 8, res = 600) + GDP_SUB_REGION_PLOT dev.off() + + +GDP_REGION_SUMMARY <- GDP %>% mutate(Region=factor(ifelse(Region=='Lincoln','Lincoln','Rest of Wyoming'),levels=rev(c('Lincoln','Rest of Wyoming')))) %>% group_by(Region,Year) %>% summarize(GDP=sum(GDP)) %>% ungroup +GDP_PLOT <- ggplot(GDP_REGION_SUMMARY ,aes(x=Year,y=GDP,fill=Region))+geom_area(position='stack')+scale_x_continuous(breaks=c(2029,seq(2025,2060,by=2)))+scale_y_continuous(labels = scales::comma,breaks=seq(0,1000,by=10))+theme(legend.position = "top")+theme_bw()+ylab("GDP (Million USD)")+scale_fill_manual(values=c(paletteer_d("PNWColors::Shuksan2")[c(5)],"mediumpurple4"))+theme(legend.position = "top") + +png(paste0(OUTPUT_DIR,"GDP_Region_Plot.png"), units = "in", width = 10, height = 8, res = 600) + GDP_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 <- read_csv(paste0(DATA_DIR,'Employment- By Industry - Employment by Industry.csv'),skip=5) %>% pivot_longer(c(-Industry,-Units),names_to="Year",values_to="Jobs") %>%mutate(Year=parse_number(Year)) %>% filter(Industry!='All Industries') %>% select(-Units) %>% filter(Year>=2029) INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='Data processing, hosting, and related services; Other information services',"Data processing",INDUSTRY_JOBS$Industry) INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='Professional, scientific, and technical services',"Technical services",INDUSTRY_JOBS$Industry) INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='Administrative and support services',"Administrative services",INDUSTRY_JOBS$Industry) @@ -78,13 +79,15 @@ INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='Food services and drin INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='Other transportation equipment manufacturing',"Equipment manufacturing",INDUSTRY_JOBS$Industry) INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='Repair and maintenance',"Maintenance",INDUSTRY_JOBS$Industry) INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='Utilities',"Energy Production",INDUSTRY_JOBS$Industry) +INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='Ambulatory health care services',"Hospitals",INDUSTRY_JOBS$Industry) -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) +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) %>% ungroup +#INDUSTRY_JOBS %>% pull(Industry) %>% unique 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) @@ -95,21 +98,56 @@ png(paste0(OUTPUT_DIR,"Job_Dist_Plot.png"), units = "in", width = 22, height = 1 dev.off() -JOB_FACET <- ggplot(INDUSTRY_JOBS %>% filter(Year %in% c(2032,2033,2045,2060)),aes(x=factor(Year),y=Jobs,fill=factor(Year)))+geom_bar(stat='identity',width=0.99)+facet_wrap(.~Industry)+theme_bw()+xlab("Year")+theme(text=element_text(size=16),legend.position="top",palette.colour.discrete=c("darkslategray1","darkslategray3","darkorchid1","darkorchid3" ))+scale_fill_discrete(name = "Year") +scale_y_continuous(labels = scales::comma,breaks=seq(0,1000,by=100)) -JOB_FACET +JOB_FACET <- ggplot(INDUSTRY_JOBS %>% filter(Year %in% c(2032,2040)),aes(x=factor(Year),y=Jobs,fill=factor(Year)))+geom_bar(stat='identity',width=0.99)+facet_wrap(.~Industry)+theme_bw()+xlab("Year")+theme(text=element_text(size=16),legend.position="top",palette.colour.discrete=c("darkslategray1","darkorchid1" ))+scale_fill_discrete(name = "Year") +scale_y_continuous(labels = scales::comma,breaks=seq(0,1000,by=100)) png(paste0(OUTPUT_DIR,"Job_Facet_Plot.png"), units = "in", width = 11, height = 11, res = 600) JOB_FACET dev.off() - ##################GDP -GDP <- read_csv(paste0(DATA_DIR,'Gross Domestic Product - By Component - GDP Components.csv'),skip=5)%>% select(-Units) %>% pivot_longer(c(-Category),names_to="Year") %>% mutate(value=parse_number(value)/1000,Year=parse_number(Year)) %>% filter(Year>=2029) -GDP <- GDP %>% filter(Category %in% c('Gross Domestic Product (GDP)','Consumption','Investment','Change in Private Inventories','Net Trade','Government Spending','Exogenous Final Demand')) -GDP_TOTAL <- GDP %>% filter(Category=='Gross Domestic Product (GDP)') %>% select(-Category) %>% rename(GDP=value) -GDP <- GDP %>% filter(Category!='Gross Domestic Product (GDP)') +GDP_TOTAL <- read_csv(paste0(DATA_DIR,'Gross Domestic Product - By Component - GDP Components.csv'),skip=5)%>% select(-Units) %>% pivot_longer(c(-Category),names_to="Year") %>% mutate(value=value*1000,Year=parse_number(Year)) %>% filter(Year>=2029) + +GDP_TOTAL <- GDP_TOTAL %>% filter(Category %in% c('Gross Domestic Product (GDP)','Consumption','Investment','Change in Private Inventories','Net Trade','Government Spending','Exogenous Final Demand')) +GDP_TOTAL <- GDP_TOTAL %>% filter(Category=='Gross Domestic Product (GDP)') %>% select(-Category) %>% rename(GDP=value) GDP_PLOT <- ggplot(GDP_TOTAL ,aes(x=Year,y=GDP))+geom_line(linewidth=1,color='slateblue')+theme_bw()+theme(text=element_text(size=16),legend.position="top")+ylab("Wyoming GDP (Million USD)")+scale_x_continuous(breaks=c(seq(2030,2060,by=2)))+scale_y_continuous(breaks=seq(0,500,by=25)) -png(paste0(OUTPUT_DIR,"GDP_Plot.png"), units = "in", width = 11, height = 8, res = 600) +png(paste0(OUTPUT_DIR,"GDP_Time_Plot.png"), units = "in", width = 11, height = 8, res = 600) GDP_PLOT dev.off() +################Personal Income +PERSONAL_INCOME <- read_csv(paste0(DATA_DIR,'Personal Income - By Region - Personal Income by Region.csv'),skip=5)%>% select(-Units) %>% pivot_longer(c(-Region),names_to="Year") %>% mutate(value=value*1000,Year=parse_number(Year)) %>% filter(Year>=2029) %>% rename(Income=value) + +TOTAL_PERSONAL_INCOME <- PERSONAL_INCOME %>% filter(Region=='All Regions') %>% select(-Region) +TOTAL_PERSONAL_INCOME + + + + +DOLLAR_VALUES <- rbind(OUTPUT_NUM %>% filter(Category=='Total') %>% select(-Category) %>% mutate(Metric='Economic Output') %>% rename('Million (USD)'=Output), +GDP_TOTAL %>% mutate(Metric='GDP') %>% rename('Million (USD)'=GDP), +TOTAL_PERSONAL_INCOME %>% mutate(Metric='Taxes STAND-IN!',Income=3*Income) %>% rename('Million (USD)'=Income), +TOTAL_PERSONAL_INCOME %>% mutate(Metric='Wages Paid') %>% rename('Million (USD)'=Income)) +FACET_INDICATORS_PLOT <- ggplot(DOLLAR_VALUES, aes(x=Year,y=`Million (USD)`,fill=Metric))+geom_area()+facet_wrap(.~Metric,nrow=2)+theme_bw()+scale_x_continuous(breaks=c(2029,seq(2025,2060,by=2)))+scale_y_continuous(labels = scales::comma,breaks=seq(0,3000,by=50))+theme(legend.position = "top",text=element_text(size=16))+scale_fill_manual(values=paletteer::paletteer_d("calecopal::lupinus") ) + +png(paste0(OUTPUT_DIR,"Facet_Indicator_Plot.png"), units = "in", width = 1.5*11, height = 1.5*10, res = 600) + FACET_INDICATORS_PLOT +dev.off() + + + +############# +Period_Indicator_Summary <- rbind(OUTPUT_NUM %>% filter(Category=='Total') %>% mutate(Period=ifelse(Year<=2033,"Construction","Operation")) %>% group_by(Period) %>% summarize(Metric='Economic Output','Average'=mean(Output),Max=max(Output)),GDP %>% mutate(Period=ifelse(Year<=2033,"Construction","Operation")) %>% group_by(Period) %>% summarize(Metric='GDP',Average=mean(GDP),Max=max(GDP)),EMPLOY_NUM %>% mutate(Period=ifelse(Year<=2033,"Construction","Operation")) %>% group_by(Period) %>% summarize(Metric='Employment',Average=mean(Employment),Max=max(Employment))) +Period_Indicator_Summary[,c(3:4)] <- round(Period_Indicator_Summary[,c(3:4)],0) +Period_Indicator_Summary + +write_csv(Period_Indicator_Summary,paste0(OUTPUT_DIR,"Economic_Summary_Indicator.csv" ),col_names=TRUE) + +GDP_SUMMARY <- GDP %>% group_by(Year) %>% summarize(GDP=sum(GDP),NPV_3=(GDP/((1+0.03)^(Year-2029))),NPV_5=(GDP/((1+0.05)^(Year-2029))),NPV_7=(GDP/((1+0.07)^(Year-2029)))) %>% ungroup +NPV_3 <- GDP_SUMMARY %>% pull(NPV_3) %>% sum +NPV_5 <- GDP_SUMMARY %>% pull(NPV_5) %>% sum +NPV_7 <- GDP_SUMMARY %>% pull(NPV_7) %>% sum +NPV_SUMMARY <- round(t(c(NPV_3,NPV_5,NPV_7)),0) %>% as_tibble +colnames(NPV_SUMMARY) <- c('3%','5%','7%') +write_csv(NPV_SUMMARY,paste0(OUTPUT_DIR,"GDP_Net_Present_Value.csv" )) + +