Improving figures

This commit is contained in:
Alex 2026-03-18 15:11:58 -06:00
parent 62083a0547
commit 735df0cfe9

View File

@ -1,5 +1,7 @@
library(tidyverse)
#install.packages("paletteer")
install.packages("waffle")
library(scales)
library(paletteer)
DATA_DIR <- 'Results/REMI_Output/'
@ -50,6 +52,20 @@ 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 <- 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)
INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='State and Local Government',"Government",INDUSTRY_JOBS$Industry)
INDUSTRY_JOBS$Industry <- ifelse(INDUSTRY_JOBS$Industry=='Food services and drinking places',"Restaurants",INDUSTRY_JOBS$Industry)
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_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)
@ -57,11 +73,12 @@ INDUSTRY_JOBS <- INDUSTRY_JOBS %>% group_by(Year) %>% mutate(Rank=rank(-Jobs)
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)
JOB_TYPE_PLOT <- ggplot(INDUSTRY_JOBS ,aes(x=Year,y=Jobs,fill=Industry))+geom_bar(stat='identity')+ paletteer::scale_fill_paletteer_d("colorBlindness::Blue2DarkRed18Steps")
png(paste0(OUTPUT_DIR,"Job_Dist_Plot.png"), units = "in", width = 20, height = 8, res = 600)
JOB_TYPE_PLOT <- ggplot(INDUSTRY_JOBS ,aes(x=Year,y=Jobs,fill=Industry))+geom_bar(stat='identity')+ paletteer::scale_fill_paletteer_d("colorBlindness::Blue2DarkRed18Steps")+theme_bw()+theme(text = element_text(size = 20),legend.position = "top")+guides(fill=guide_legend(nrow=2,byrow=TRUE)) +scale_x_continuous(breaks=seq(2029,2060,by=1))+scale_y_continuous(labels = scales::comma,breaks=seq(0,3000,by=250))
png(paste0(OUTPUT_DIR,"Job_Dist_Plot.png"), units = "in", width = 22, height = 16, res = 600)
JOB_TYPE_PLOT
dev.off()
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")
ggplot(INDUSTRY_JOBS %>% filter(Year %in% c(2032,2045)),aes(x=factor(Year),y=Jobs,fill=factor(Year)))+geom_bar(stat='identity',width=0.99)+facet_wrap(.~Industry)+theme_bw()
#+ paletteer::scale_fill_paletteer_d("lisa::FridaKahlo")