---
title: "Climate policy accelerates structural changes in energy employment"
author: "Aman Malik"
date: "15-01-2021"
output:
  html_document:
    toc: true
    toc_float: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE, message=FALSE, warning=FALSE,cache = T)
```

```{r}
library(tidyverse)
library(ggpubr)
```

The following document provides high resolution figures, accompanying the main text and supplementary information. Note that these figures are unformatted and might differ slightly from the figures in the paper.

```{r input data, message=FALSE, warning=FALSE, include=FALSE}
# Loading input data
# input data includes jobs, cumulative capacity, new capacity, production for all the two scenarios (NDC and Pol/1.5C) and the 4 EF-scenarios.
load(file = "data/jobs_2021-01-14.RData")
```

```{r params,message=F,include=F}
# initialising parameters
techs <- c("Solar|PV","Solar|PV-utility","Solar|PV-rooftop","Wind","Wind onshore", "Wind offshore","Hydro","Hydro-large","Hydro-small","Biomass","Coal","Gas","Nuclear","Oil","Geothermal","Storage-battery","Solar|CSP")

myColors <- c("#ffcc00","#ffe600","#7f7f00","#337fff","#7f99cc","#99bfff","#191999","#66cccc","#88FFFF","#005900","#b2b2b2","#999959","#ff33ff","#663a00","#e51900","#9500da","#ffb400","#1B9E77","#D95F02","#7570B3","#E6AB02")

names(myColors) <- c(techs,"CI","OM","Fuel_supply","Manf")

```


## Figure 2
```{r figure 1}

# Figure 1a and 1b
fuel <- df %>% filter(Variable=="Jobs",comb2!="no LP no capcosts") %>%  
               mutate(type=ifelse(Tech%in% c("Coal","Oil","Gas"),"fossil","non-fossil")) %>%  group_by(Year,Scenario,type,comb2) %>% 
  summarise(Value=sum(Value)) %>% 
               ungroup() %>% 
  spread(type,value = "Value") %>% 
  mutate(total=`fossil`+`non-fossil`) %>% 
  mutate(`nf_share`=(`non-fossil`/`total`)*100)

fuel2 <- df %>% filter(Variable=="Jobs",comb2!="no LP no capcosts") %>%  
               mutate(type=ifelse(Tech%in% c("Coal","Oil","Gas"),"fossil","non-fossil")) %>%  group_by(Year,Scenario,type,comb2,Tech) %>% 
  summarise(Value=sum(Value)) %>% 
               ungroup()

  oa_all1 <-  ggplot()+
  geom_line(fuel %>% gather(4:7,key = "type",value = "value") %>% filter(Year>2015,type!="nf_share",comb2=="both LP and capcosts"),mapping = aes(x=Year,y=value,linetype=Scenario,color=type),stat="identity",size=1.1)+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
 labs(x="",y="")+
  theme_bw()

oa_all2 <- ggplot()+
  geom_line(fuel2 %>% filter(Year>2015,comb2=="both LP and capcosts",!Tech %in% c("Solar|CSP","Geothermal")),mapping = aes(x=Year,y=Value,color=Tech,group=interaction(Scenario,Tech),linetype=Scenario),stat="identity")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  labs(x="",y="")+
   scale_colour_manual(values=myColors,aesthetics = "color")+
  theme_bw()

mine <- ggpubr::ggarrange(oa_all1,oa_all2,ncol = 1,align = "v",labels = c("a","b"))
mine

# Figure 1c and 1d
cutie <- df %>%filter(Variable=="Jobs",Value>0) %>% group_by(Tech,Scenario,comb2,Activity,Year) %>% summarise(Value=sum(Value))

cutie2 <- df %>%filter(Variable=="Jobs",Value>0) %>% group_by(Scenario,comb2,Activity,Year) %>% summarise(Value=sum(Value)) %>% mutate(Tech="All")

# for jobs in 2020

cutieplot_all <- ggplot()+
geom_col(cutie2 %>% filter(Year==2020,Scenario=="NDC",comb2=="both LP and capcosts"),mapping = aes(x=Tech,y=Value,fill=Activity))+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "Jobs in 2020")+
  theme(text = element_text(size = 12))+
  theme_bw()

cutieplot <- ggplot()+
  geom_col(cutie %>% filter(Year==2020,comb2=="both LP and capcosts",Scenario=="NDC",!Tech %in%  c("Solar|CSP","Geothermal")), mapping = aes(x=Tech,y=Value,fill=Activity))+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "")+
  theme(text = element_text(size = 12))+
  theme_bw()

twenty <- ggarrange(cutieplot_all,cutieplot,nrow=1,common.legend = T,widths = c(1,2))

# for jobs in 2050

cutieplot2_all <- ggplot()+
  geom_col(cutie2 %>% filter(Year==2050,comb2=="both LP and capcosts"),mapping = aes(x=Tech,y=Value,fill=Activity))+
  facet_grid(Scenario~.)+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "Jobs in 2050")+
  theme_bw()+
  theme(text = element_text(size = 12),
  strip.background = element_blank(),
  strip.text = element_blank()
)

cutieplot2 <- ggplot()+
  geom_col(cutie %>% filter(Year==2050,comb2=="both LP and capcosts",Tech %in% c("Coal","Oil","Gas","Biomass","Hydro","Wind","Solar|PV")),mapping = aes(x=Tech,y=Value,fill=Activity))+
    facet_grid(Scenario~.,)+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "")+
  theme(text = element_text(size = 12))+
  theme_bw()
fifty <- ggarrange(cutieplot2_all,cutieplot2,nrow=1,legend = "none",widths = c(1,2))

twenty_fifty <- ggarrange(twenty,fifty,ncol = 1,labels = c("c","d"),common.legend = T,heights = c(1,2))
twenty_fifty

```

## Figure 3
```{r }

cap <-  df %>% filter(Variable=="Cap",comb=="static+static",Year %in% c(2020,2030)) %>%  
  group_by(Year,Scenario,Tech) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup() %>% 
  spread(Year,value = Value) %>% 
  mutate(Delta=(`2030`-`2020`)/`2020`) %>% 
  gather(c(`2030`,`2020`),key = "Year",value = Value) %>% 
  mutate(type="Cumulative Capacity (GW)")
  

production <-  df %>% filter(Variable=="Production",comb=="static+static",!is.na(Value),Year %in% c(2020,2030)) %>%  
  group_by(Year,Scenario,Tech) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup() %>% 
  spread(Year,value = Value) %>% 
  mutate(Delta=(`2030`-`2020`)/`2020`) %>% 
  gather(c(`2030`,`2020`),key = "Year",value = Value)%>% 
  mutate(type="Production (EJ)")

## Elasticity divided for capacity and production

# first capacity
jobs_delta_cap <- df %>% 
  filter(!is.na(Value),Value>0,Variable=="Jobs", Year %in% c(2030,2020),comb2=="both LP and capcosts",Activity!="Fuel_supply") %>% 
  group_by(Year,Scenario,Tech) %>% 
  summarise(Value=sum(Value)) %>%
  ungroup()  %>% 
  spread(Year,value = Value) %>% 
  mutate(Delta=(`2030`-`2020`)/`2020`) %>% 
  gather(c(`2020`,`2030`),key = "Year",value = "Value")

blah <- left_join(cap,jobs_delta_cap,by = c("Scenario", "Tech","Year")) %>% mutate(ela=Delta.y/Delta.x) 

# then production
jobs_delta_prod <- df %>% 
  filter(!is.na(Value),Value>0,Variable=="Jobs", Year %in% c(2030,2020),comb2=="both LP and capcosts",Activity=="Fuel_supply") %>% 
  group_by(Year,Scenario,Tech) %>% 
  summarise(Value=sum(Value)) %>%
  ungroup()  %>% 
  spread(Year,value = Value) %>% 
  mutate(Delta=(`2030`-`2020`)/`2020`) %>% 
  gather(c(`2020`,`2030`),key = "Year",value = "Value")  


blah2 <- left_join(production,jobs_delta_prod,by = c("Scenario", "Tech","Year")) %>% mutate(Delta.x=Delta.x,ela=Delta.y/Delta.x)

# joining

blah_all <- bind_rows(blah,blah2) %>% filter(Year==2030) %>% select(Scenario,Tech,ela,type,Delta.x,Delta.y)

export_blah <- ggplot()+
  geom_point(blah_all,mapping = aes(x=Delta.x*100,y = Delta.y*100,color=Tech),size=3)+
  facet_grid(Scenario~type)+
  scale_colour_manual(values=myColors,aesthetics = "color")+
  labs(x="Rel, percentage Change in Cumulative Capacity or Production (%)",y="Rel. percentage change in jobs(%)")+
  geom_abline(slope=1)+
  theme(text=element_text(size = 10))+theme_bw()

# Jobs by EF scenarios
pol_others <- df %>% 
  filter(!is.na(Value),Value>0,Variable=="Jobs", Year %in% c(2030,2020)) %>% 
  group_by(Year,Scenario,comb2,Activity,Tech) %>% 
  summarise(Value=sum(Value)) %>%
  ungroup()  %>% 
  spread(Year,value = Value) %>% 
  mutate(Delta=`2030`-`2020`) %>% 
  gather(c(`2020`,`2030`),key = "Year",value = "Value") %>% 
  filter(!is.na(Delta))

# Jobs by tech only
pol_others_tech <- df %>% 
  filter(!is.na(Value),Value>0,Variable=="Jobs", Year %in% c(2030,2020)) %>% 
  group_by(Year,Scenario,comb2,Tech) %>% 
  summarise(Value=sum(Value)) %>%
  ungroup()  %>% 
  spread(Year,value = Value) %>% 
  mutate(Delta=`2030`-`2020`) %>% 
  gather(c(`2020`,`2030`),key = "Year",value = "Value") %>% 
  filter(!is.na(Delta))

haha_tech <- ggplot(pol_others_tech %>% 
        filter(comb2 %in% c("both LP and capcosts"),Year==2030))+
    geom_bar(aes(x=Year,y=Delta,fill=Tech),stat="identity")+
    facet_wrap(Scenario~.,nrow = 1)+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
    labs(x="",y="",subtitle = "2030-2020 jobs")+
   scale_colour_manual(values=myColors,aesthetics = "fill")+
  theme(axis.text.x = element_text(angle = 90))+
  geom_point(pol_others_tech %>% filter(Year==2030) %>% group_by(Scenario,comb2,Year) %>% summarise(Delta=sum(Delta)) %>% filter(comb2 %in% c("both LP and capcosts")),
             mapping = aes(x=Year,y=Delta,shape=comb2),shape="cross",size=2,stroke=2)+
  theme_bw()
      
## Jobs comparing NDC and Pol for EF scenario 
haha_3 <- ggplot(pol_others %>% 
        filter(comb2 %in% c("both LP and capcosts"),Year==2030))+
    geom_bar(aes(x=Activity,y=Delta,fill=Tech),stat="identity")+
    facet_wrap(Scenario~.,nrow = 1)+
  theme_bw()+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
    labs(x="",y="",subtitle = "2030-2020 jobs")+
   scale_colour_manual(values=myColors,aesthetics = "fill")+
  theme(axis.text.x = element_text(angle = 90))

arrange_diff <- ggarrange(haha_tech,haha_3,export_blah,labels=c("a","b","c"),common.legend = T,legend = "right")
arrange_diff  

```

## Figure S1
```{r}

load(file = "data/adj_fac.RData")
adj_fac <- adj_fac %>% select(-1) %>% mutate(Year=as.factor(Year))
perfect <- ggplot()+
      geom_point(adj_fac,mapping = aes(x=1/Value,y=Year,color=Region,size=2),show.legend = F)+
      ggrepel::geom_label_repel(adj_fac,mapping = aes(x=1/Value,y=Year,label=Region),min.segment.length = 0.2,nudge_y = 0.3)+
      labs(x="Regional adjustment factor in 2020",y="")+
      theme_bw()
      perfect
```

## Figure S2
## Figure S3
```{r }

load(file = "data/efs_for_upload.RData")

# CI, Manf and O & M
b_2020 <- ggplot(x_own %>% filter(Year==2020,Activity!="Fuel_supply"))+
  geom_point(aes(x=Value,y=Tech,color=Activity))+
  facet_wrap(Region~.)+
   theme(strip.text.y = element_text(angle = 0),legend.position = "top",legend.title = element_blank())+
      coord_cartesian(xlim=c(0,100))+
  labs(x="Employment factor (FTE/MW)",y="",tag = "a")
b_2020

# Fuel supply
a_2020 <- ggplot(x_own %>% filter(Year==2020,Activity=="Fuel_supply",Value!=0,Tech!="Nuclear"))+
  geom_point(aes(x=Value,y=Tech,color=Activity))+
  facet_wrap(Region~.)+
   theme(strip.text.y = element_text(angle = 0),legend.position = "top",legend.title = element_blank())+
      coord_cartesian(xlim=c(0,400))+
  labs(x="Employment factor (FTE/PJ)",y="",tag = "b")
a_2020

```

## Figure S4
```{r}
load(file = "data/coal_ef.RData")
coal_ef <- ggplot()+
  geom_line(coal_ef %>% filter(Value!=0,Year>2019), mapping = aes(x=Year,y=Value,color=Region,group=Region),linetype="solid")+
  labs(x="",y="Employment factor (Jobs/PJ)")+
  scale_color_brewer(type = "qual",palette = "Dark2")+
  geom_line(coal_ef %>% filter(Value!=0,Year %in% c(2005:2020)), mapping = aes(x=Year,y=Value,color=Region,group=Region),linetype="dashed")

coal_ef
                                                                  
```

## Figure S5 
```{r}
load(file = "data/IRENA_df.RData")

# REMIND
remind_jobs <- df %>% filter(Scenario=="NDC", comb2=="only LP",Variable=="Jobs") %>% group_by(Tech,Year,Scenario,Region) %>% summarise(Value=sum(Value))

irena_techs <- c("Biomass","Solar|PV","Hydro","Hydro-large","Hydro-small","Solar|CSP","Wind","Geothermal")

com_techs <- intersect(unique(remind_jobs$Tech),unique(IRENA_df$Tech))

## world
## 
iea <- data.frame(Tech=c("Coal", "Oil", "Gas","Solar|PV","Wind","Hydro","Nuclear","Biomass"),Value=c(8.2,8.4,5.9,3.4,1,2,0.8,3),Source="IEA",Year="2020")
iea$Value <- iea$Value*1000000

glo <-  ggplot()+
  geom_bar(data = IRENA_df %>% filter(Year==2020,Region %in% "GLO",Tech %in% com_techs),
            aes(x=Source,y=Value,fill=Tech),stat = "identity",position="dodge")+
   labs(y="", x="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+
  geom_bar(remind_jobs %>% group_by(Year,Tech) %>% summarise(Value=sum(Value)) %>% ungroup() %>% filter(Year=="2020",Tech %in% c(com_techs,"Coal","Gas","Oil","Nuclear")) %>% mutate(Source="REMIND",Region="GLO"),mapping = aes(x=Source,y = Value,fill=Tech),stat = "identity",position = "dodge")+
  geom_bar(iea,mapping = aes(x=Source,y=Value,fill=Tech),stat = "identity",position = "dodge")+
  facet_wrap(Region~.,nrow = 1)+
  labs(caption = "IEA and IRENA data for 2019, REMIND for 2020.
  IEA includes refining, transportation, and distribution jobs for coal, oil, gas, and bioenergy;
  REMIND includes only direct jobs in fuel production/extraction.
  Biomass jobs for IRENA is sum of Biomass, 80% Biofuels, and 30% Biogas jobs")+
  theme(plot.caption = element_text(size = 6))

glo

```


## Figure S6
```{r}

# for USA
solar_found <- data.frame(Tech="Solar|PV",Activity=c("CI","OM","Manf"),Year=2020,Source="Solar Foundation",Value=c(169202,11273,34949),Region="USA")

usa <- ggplot()+
  geom_bar(IRENA_df %>% filter(Year==2020,Region %in% "USA",Tech %in% com_techs),mapping = 
              aes(x=Source,y=Value,fill=Tech),stat = "identity",position="dodge")+
  geom_bar(solar_found,mapping = aes(x=Source,y=Value,fill=Tech),stat = "identity",width = 0.3) +
  geom_bar(remind_jobs %>% filter(Year=="2020",Region %in% "USA",Tech %in% c(com_techs)) %>% mutate(Source="REMIND"),mapping = aes(x=Source,y = Value,fill=Tech),stat = "identity",position = "dodge")+
    facet_wrap(Region~.,nrow = 1)+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+
     labs(y="", x="")+
  theme(plot.caption = element_text(size = 8))

# for EUR
  
load(file = "data/Eurob_df.RData")

load(file = "data/Dias_df.RData")

eur <- ggplot()+
  geom_bar(data = IRENA_df %>% filter(Year==2020,Region %in% "EUR",Tech %in% com_techs),
            aes(x=Source,y=Value,fill=Tech),stat = "identity",position="dodge")+
   labs(y="", x="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+
  geom_bar(remind_jobs %>% filter(Year=="2020",Region %in% "EUR",Tech %in% c(com_techs,"Coal")) %>% mutate(Source="REMIND"),mapping = aes(x=Source,y = Value,fill=Tech),stat = "identity",position = "dodge")+
  facet_wrap(Region~.,nrow = 1)+
  geom_bar(Eurob_df %>% filter(Year==2018,Tech %in% com_techs),mapping = aes(x=Source,y=Value,fill=Tech),stat = "identity",position = "dodge")+
  geom_bar(Dias_df %>% filter(Type=="direct"),mapping = aes(x=Source,y=Value,fill=Tech),stat = "identity")+
  # labs(caption = "Dias et al. values for 2015, Eurobserver for 2018, IRENA for 2019. 
  #      Euobserver includes both direct and indirect jobs")+
  theme(plot.caption = element_text(size = 8))


# for IND
load(file = "data/CEEW_df.RData")

com_techs <- c("Solar|PV","Biomass","Hydro","Wind")

ind <- ggplot()+
  geom_bar(data = IRENA_df %>% filter(Year==2020,Region %in% "IND",Tech %in% com_techs),
            aes(x=Source,y=Value,fill=Tech),stat = "identity",position="dodge")+
   labs(y="", x="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+
  geom_bar(remind_jobs %>% filter(Year=="2020",Region %in% "IND",Tech %in% com_techs) %>% mutate(Source="REMIND"),mapping = aes(x=Source,y = Value,fill=Tech),stat = "identity",position = "dodge")+
  facet_wrap(Region~.,nrow = 1)+
  geom_bar(CEEW_df %>% filter(Year==2018,Tech %in% com_techs),mapping = aes(x=Source,y=Value,fill=Tech),stat = "identity",position = "dodge")+
  # labs(caption = "CEEW data is from 2018, IRENA for 2019")+
  theme(plot.caption = element_text(size = 8))
  
## for CHN
chn <- ggplot()+
  geom_bar(data = IRENA_df %>% filter(Year==2020,Region %in% "CHN",Tech %in% com_techs),
            aes(x=Source,y=Value,fill=Tech),stat = "identity",position="dodge")+
   labs(y="", x="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+
  geom_bar(remind_jobs %>% mutate(Region=gsub("CHA",replacement = "CHN",Region,fixed = T)) %>% filter(Year=="2020",Region %in% "CHN",Tech %in% com_techs) %>% mutate(Source="REMIND"),mapping = aes(x=Source,y = Value,fill=Tech),stat = "identity",position = "dodge")+
  facet_wrap(Region~.,nrow = 1)+
  # labs(caption = "IRENA values from 2019.")+
  theme(plot.caption = element_text(size = 8))

# rest of the world

row <-  ggplot()+
  geom_bar(data = IRENA_df %>% filter(Tech %in% com_techs,Year==2020,!(Region %in% c("IND","EUR","USA","CHN","GLO"))) %>% group_by(Tech,Year) %>% summarise(Value=sum(Value)) %>% mutate(Region="RoW",Source="IRENA"),
            aes(x=Source,y=Value,fill=Tech),stat = "identity",position="dodge")+
   labs(y="", x="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+
  geom_bar(remind_jobs %>% filter(!(Region %in% c("IND","EUR","USA","CHA")), Year=="2020",Tech %in% com_techs) %>% group_by(Year,Tech) %>% summarise(Value=sum(Value)) %>%  mutate(Source="REMIND",Region="RoW"), 
           mapping = aes(x=Source,y = Value,fill=Tech),stat = "identity",position = "dodge")+
  facet_wrap(Region~.,nrow = 1)

arrange2 <- ggarrange(eur,usa,ind,chn,row,labels = c("a","d","b","e","c"),legend = "right",common.legend = T,nrow=3,ncol=2)

arrange2



```
## Figure S7
```{r}

load(file = "data/laborprod.Rdata")
a <- ggplot()+geom_point(historical %>% filter(Year>1960),mapping = aes(x=lp/1000,y=gdppc/1000,color=RegionCode),size=1,show.legend = F)+
  labs(x="Labor productivity per person (in 000s) employed in 2019 US$",y="Per capita GDP (in 000s) 2019 US$")+
  facet_wrap(RegionCode~.,scales = "free")+
  ggrepel::geom_text_repel(historical %>% filter(Year %in% c(seq(1960,2019,10),2019)),mapping = aes(x=lp/1000,y=gdppc/1000,label=Year),size=2,show.legend = F)

a
```

## Figure S8
```{r}
load(file = "data/wageshare.RData")
colnames(df3)[4:14] <- c("Coal","Gas","Hydro","Nuclear","Solar|PV","Solar|CSP","Wind","Biomass","Batttery","Oil","Geothermal")

df3 <- df3 %>% gather(4:14,key = "Tech",value = "Value") %>% 
  mutate(Year=as.integer(as.character(Year)))

load(file = "data/GDPpc.RData")

# Bring in EF
x_own2 <- x_own%>% 
  mutate(Tech=gsub("Solar|PV-utility",replacement = "Solar|PV",Tech,fixed = T),
         Tech=gsub("Hydro-large",replacement = "Hydro",Tech,fixed = T),
         Tech=gsub("Wind onshore",replacement = "Wind",Tech,fixed = T)) %>% 
  filter(Value>0) %>% 
  select(-comb,-Variable) %>% 
  filter(Activity %in% c("CI","Manf")) %>% 
   spread(Activity,value = Value) %>% 
    mutate(CI_Manf=`CI`+`Manf`) %>% 
  gather(6:8,key = "Activity",value = "Value" )


lc <- left_join(x_own2 %>% filter(Activity =="CI_Manf"),GDPpc,by =c("Year","Region"))
lc <- lc %>% mutate(labor_costs=Value.x*Value.y) 
  

# wage share
ws <- left_join(lc,df3,by=c("Year","Region","Tech","Scenario")) %>% 
  mutate(Value=Value*1000) %>% # from ed /KW to USD per MW
  mutate(wage_shr=labor_costs/Value) %>% 
  filter(!is.na(wage_shr)) %>% 
  rename(EF="Value.x",
         Wage="Value.y",
         Capital_costs="Value")

# plotting
plotting <- ggplot()+
  geom_line(ws %>% filter(Scenario=="Pol",Tech=="Solar|PV",comb2!="no LP no capcosts"),mapping = aes(x=Year,y=wage_shr,color=Region,group=interaction(Region,comb2)))+
  facet_wrap(Tech~comb2,scales = "free")+
  labs(x="",y="Share of wage (CI and Manufacturing) in capital costs ")
plotting

```

## Figure S9
```{r}
# Figure 9a and 9b

  oa_all1 <-  ggplot()+
  geom_line(fuel %>% gather(4:7,key = "type",value = "value") %>% filter(Year>2015,type!="nf_share",comb2=="only LP"),mapping = aes(x=Year,y=value,linetype=Scenario,color=type),stat="identity",size=1.1)+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
 labs(x="",y="")+
  theme_bw()

oa_all2 <- ggplot()+
  geom_line(fuel2 %>% filter(Year>2015,comb2=="only LP",!Tech %in% c("Solar|CSP","Geothermal")),mapping = aes(x=Year,y=Value,color=Tech,group=interaction(Scenario,Tech),linetype=Scenario),stat="identity")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  labs(x="",y="")+
   scale_colour_manual(values=myColors,aesthetics = "color")+
  theme_bw()

mine <- ggpubr::ggarrange(oa_all1,oa_all2,ncol = 1,align = "v",labels = c("a","b"))
mine

# Figure 9c and 9d


# for jobs in 2020

cutieplot_all <- ggplot()+
geom_col(cutie2 %>% filter(Year==2020,Scenario=="NDC",comb2=="only LP"),mapping = aes(x=Tech,y=Value,fill=Activity))+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "Jobs in 2020")+
  theme(text = element_text(size = 12))+
  theme_bw()

cutieplot <- ggplot()+
  geom_col(cutie %>% filter(Year==2020,comb2=="only LP",Scenario=="NDC",!Tech %in%  c("Solar|CSP","Geothermal")), mapping = aes(x=Tech,y=Value,fill=Activity))+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "")+
  theme(text = element_text(size = 12))+
  theme_bw()

twenty <- ggarrange(cutieplot_all,cutieplot,nrow=1,common.legend = T,widths = c(1,2))

# for jobs in 2050

cutieplot2_all <- ggplot()+
  geom_col(cutie2 %>% filter(Year==2050,comb2=="only LP"),mapping = aes(x=Tech,y=Value,fill=Activity))+
  facet_grid(Scenario~.)+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "Jobs in 2050")+
  theme_bw()+
  theme(text = element_text(size = 12),
  strip.background = element_blank(),
  strip.text = element_blank()
)

cutieplot2 <- ggplot()+
  geom_col(cutie %>% filter(Year==2050,comb2=="only LP",Tech %in% c("Coal","Oil","Gas","Biomass","Hydro","Wind","Solar|PV")),mapping = aes(x=Tech,y=Value,fill=Activity))+
    facet_grid(Scenario~.,)+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "")+
  theme(text = element_text(size = 12))+
  theme_bw()
fifty <- ggarrange(cutieplot2_all,cutieplot2,nrow=1,legend = "none",widths = c(1,2))

twenty_fifty <- ggarrange(twenty,fifty,ncol = 1,labels = c("c","d"),common.legend = T,heights = c(1,2))
twenty_fifty
```

## Figure S10
```{r}
# Figure 10a and 10b

  oa_all1 <-  ggplot()+
  geom_line(fuel %>% gather(4:7,key = "type",value = "value") %>% filter(Year>2015,type!="nf_share",comb2=="only capcosts"),mapping = aes(x=Year,y=value,linetype=Scenario,color=type),stat="identity",size=1.1)+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
 labs(x="",y="")+
  theme_bw()

oa_all2 <- ggplot()+
  geom_line(fuel2 %>% filter(Year>2015,comb2=="only capcosts",!Tech %in% c("Solar|CSP","Geothermal")),mapping = aes(x=Year,y=Value,color=Tech,group=interaction(Scenario,Tech),linetype=Scenario),stat="identity")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  labs(x="",y="")+
   scale_colour_manual(values=myColors,aesthetics = "color")+
  theme_bw()

mine <- ggpubr::ggarrange(oa_all1,oa_all2,ncol = 1,align = "v",labels = c("a","b"))
mine

# Figure 10c and 10d


# for jobs in 2020

cutieplot_all <- ggplot()+
geom_col(cutie2 %>% filter(Year==2020,Scenario=="NDC",comb2=="only capcosts"),mapping = aes(x=Tech,y=Value,fill=Activity))+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "Jobs in 2020")+
  theme(text = element_text(size = 12))+
  theme_bw()

cutieplot <- ggplot()+
  geom_col(cutie %>% filter(Year==2020,comb2=="only capcosts",Scenario=="NDC",!Tech %in%  c("Solar|CSP","Geothermal")), mapping = aes(x=Tech,y=Value,fill=Activity))+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "")+
  theme(text = element_text(size = 12))+
  theme_bw()

twenty <- ggarrange(cutieplot_all,cutieplot,nrow=1,common.legend = T,widths = c(1,2))

# for jobs in 2050

cutieplot2_all <- ggplot()+
  geom_col(cutie2 %>% filter(Year==2050,comb2=="only capcosts"),mapping = aes(x=Tech,y=Value,fill=Activity))+
  facet_grid(Scenario~.)+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "Jobs in 2050")+
  theme_bw()+
  theme(text = element_text(size = 12),
  strip.background = element_blank(),
  strip.text = element_blank()
)

cutieplot2 <- ggplot()+
  geom_col(cutie %>% filter(Year==2050,comb2=="only capcosts",Tech %in% c("Coal","Oil","Gas","Biomass","Hydro","Wind","Solar|PV")),mapping = aes(x=Tech,y=Value,fill=Activity))+
    facet_grid(Scenario~.,)+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  scale_colour_manual(values=myColors,aesthetics = "fill")+labs(x="",y="",subtitle = "")+
  theme(text = element_text(size = 12))+
  theme_bw()
fifty <- ggarrange(cutieplot2_all,cutieplot2,nrow=1,legend = "none",widths = c(1,2))

twenty_fifty <- ggarrange(twenty,fifty,ncol = 1,labels = c("c","d"),common.legend = T,heights = c(1,2))
twenty_fifty
```

## Figure S11 - 
```{r}
export_blah <- ggplot()+
  geom_point(blah_all,mapping = aes(x=Delta.x*100,y = Delta.y*100,color=Tech),size=3)+
  facet_grid(Scenario~type)+
  scale_colour_manual(values=myColors,aesthetics = "color")+
  labs(x="Rel, percentage Change in Cumulative Capacity or Production (%)",y="Rel. percentage change in jobs(%)")+
  geom_abline(slope=1)+
  theme(text=element_text(size = 10))+theme_bw()


haha_tech <- ggplot(pol_others_tech %>% 
        filter(comb2 %in% c("only LP"),Year==2030))+
    geom_bar(aes(x=Year,y=Delta,fill=Tech),stat="identity")+
    facet_wrap(Scenario~.,nrow = 1)+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
    labs(x="",y="",subtitle = "2030-2020 jobs")+
   scale_colour_manual(values=myColors,aesthetics = "fill")+
  theme(axis.text.x = element_text(angle = 90))+
  geom_point(pol_others_tech %>% filter(Year==2030) %>% group_by(Scenario,comb2,Year) %>% summarise(Delta=sum(Delta)) %>% filter(comb2 %in% c("only LP")),
             mapping = aes(x=Year,y=Delta,shape=comb2),shape="cross",size=2,stroke=2)+
  theme_bw()
      
## Jobs comparing NDC and Pol for EF scenario 
haha_3 <- ggplot(pol_others %>% 
        filter(comb2 %in% c("only LP"),Year==2030))+
    geom_bar(aes(x=Activity,y=Delta,fill=Tech),stat="identity")+
    facet_wrap(Scenario~.,nrow = 1)+
  theme_bw()+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
    labs(x="",y="",subtitle = "2030-2020 jobs")+
   scale_colour_manual(values=myColors,aesthetics = "fill")+
  theme(axis.text.x = element_text(angle = 90))

arrange_diff <- ggarrange(haha_tech,haha_3,export_blah,labels=c("a","b","c"),common.legend = T,legend = "right")
arrange_diff  
```

## Figure S12
```{r}
export_blah <- ggplot()+
  geom_point(blah_all,mapping = aes(x=Delta.x*100,y = Delta.y*100,color=Tech),size=3)+
  facet_grid(Scenario~type)+
  scale_colour_manual(values=myColors,aesthetics = "color")+
  labs(x="Rel, percentage Change in Cumulative Capacity or Production (%)",y="Rel. percentage change in jobs(%)")+
  geom_abline(slope=1)+
  theme(text=element_text(size = 10))+theme_bw()


haha_tech <- ggplot(pol_others_tech %>% 
        filter(comb2 %in% c("only capcosts"),Year==2030))+
    geom_bar(aes(x=Year,y=Delta,fill=Tech),stat="identity")+
    facet_wrap(Scenario~.,nrow = 1)+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
    labs(x="",y="",subtitle = "2030-2020 jobs")+
   scale_colour_manual(values=myColors,aesthetics = "fill")+
  theme(axis.text.x = element_text(angle = 90))+
  geom_point(pol_others_tech %>% filter(Year==2030) %>% group_by(Scenario,comb2,Year) %>% summarise(Delta=sum(Delta)) %>% filter(comb2 %in% c("only capcosts")),
             mapping = aes(x=Year,y=Delta,shape=comb2),shape="cross",size=2,stroke=2)+
  theme_bw()
      
## Jobs comparing NDC and Pol for EF scenario 
haha_3 <- ggplot(pol_others %>% 
        filter(comb2 %in% c("only capcosts"),Year==2030))+
    geom_bar(aes(x=Activity,y=Delta,fill=Tech),stat="identity")+
    facet_wrap(Scenario~.,nrow = 1)+
  theme_bw()+
    scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
    labs(x="",y="",subtitle = "2030-2020 jobs")+
   scale_colour_manual(values=myColors,aesthetics = "fill")+
  theme(axis.text.x = element_text(angle = 90))

arrange_diff <- ggarrange(haha_tech,haha_3,export_blah,labels=c("a","b","c"),common.legend = T,legend = "right")
arrange_diff  
```

## Figure S13
```{r}
share_plot2a <- ggplot()+
  geom_area(df %>% filter(Variable=="Jobs") %>%   
  group_by(Year,Scenario,Activity,comb2) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup()  %>% 
  filter(comb2=="both LP and capcosts",Scenario=="Pol",Year>2015), mapping = aes(x=Year,y=Value,fill=Activity))+
  labs(x="both LP and capcosts",y="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  coord_cartesian(ylim=c(0,44000000))+
  scale_colour_manual(values=myColors,aesthetics = "fill")+
  facet_wrap(Scenario~.)

df_tmp <- df %>% filter(Variable=="Jobs") %>%   
  group_by(Year,Scenario,Activity,comb2) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup()  %>% 
  filter(!comb2 %in% c("both LP and capcosts","no LP no capcosts"),Scenario=="Pol",Year==2050)

share_plot3a <- ggplot()+
   geom_col(df_tmp, mapping = aes(x=comb2,y=Value,fill=Activity),width =0.4)+
  labs(x="",y="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
   coord_cartesian(ylim=c(0,44000000))+
    theme(axis.title.y=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        axis.text.x=element_text(angle = 90))+
  scale_colour_manual(values=myColors,aesthetics = "fill")+
  facet_wrap(Scenario~.)

# plot for NDC scenarios with only 2050 values
df_tmp2 <- df %>% filter(Variable=="Jobs") %>%   
  group_by(Year,Scenario,Activity,comb2) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup()  %>% 
  filter(!comb2 %in% c("no LP no capcosts"),Scenario=="NDC",Year==2050)

share_plot4a <- ggplot()+
   geom_col(df_tmp2, mapping = aes(x=comb2,y=Value,fill=Activity),width =0.4)+
  labs(x="",y="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
   coord_cartesian(ylim=c(0,44000000))+
    theme(axis.title.y=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        axis.text.x=element_text(angle = 90))+
    scale_colour_manual(values=myColors,aesthetics = "fill")+
  facet_wrap(Scenario~.)
  
share_all <- ggpubr::ggarrange(share_plot2a,share_plot3a,share_plot4a,common.legend = T,widths = c(2,0.5,0.5),align = "h",legend = "right",nrow = 1)


share_plot2 <- ggplot()+
  geom_area(df %>% filter(Variable=="Jobs") %>%   
  group_by(Year,Scenario,Tech,comb2) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup()  %>% 
  filter(comb2=="both LP and capcosts",Scenario=="Pol",Year>2015), mapping = aes(x=Year,y=Value,fill=Tech))+
  labs(x="both LP and capcosts",y="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
  coord_cartesian(ylim=c(0,44000000))+
  scale_colour_manual(values=myColors,aesthetics = "fill")+
  facet_wrap(Scenario~.)
 
  
df_tmp <- df %>% filter(Variable=="Jobs") %>%   
  group_by(Year,Scenario,Tech,comb2) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup()  %>% 
  filter(!comb2 %in% c("both LP and capcosts","no LP no capcosts"),Scenario=="Pol",Year==2050)

share_plot3 <- ggplot()+
   geom_col(df_tmp, mapping = aes(x=comb2,y=Value,fill=Tech),width =0.4)+
  labs(x="",y="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
   coord_cartesian(ylim=c(0,44000000))+
    theme(axis.title.y=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        axis.text.x=element_text(angle = 90))+
    scale_colour_manual(values=myColors,aesthetics = "fill")+
  facet_wrap(Scenario~.)

# plot for NDC scenarios with only 2050 values
df_tmp2 <- df %>% filter(Variable=="Jobs") %>%   
  group_by(Year,Scenario,Tech,comb2) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup()  %>% 
  filter(!comb2 %in% c("no LP no capcosts"),Scenario=="NDC",Year==2050)

share_plot4 <- ggplot()+
   geom_col(df_tmp2, mapping = aes(x=comb2,y=Value,fill=Tech),width =0.4)+
  labs(x="",y="")+
  scale_y_continuous(labels = function(x) {paste0(x/1000000, 'M')})+
   coord_cartesian(ylim=c(0,44000000))+
    theme(axis.title.y=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        axis.text.x=element_text(angle = 90))+
    scale_colour_manual(values=myColors,aesthetics = "fill")+
  facet_wrap(Scenario~.)
  
share_all_tech <- ggpubr::ggarrange(share_plot2,share_plot3,share_plot4,common.legend = T,widths = c(2,0.5,0.5),align = "h",legend = "right",nrow = 1,labels = "")

share_big <- ggarrange(share_all_tech,share_all,ncol = 1,labels = c("a","b"))
share_big
```

## Figure S14
```{r}
load(file = "data/capitalcosts_b.RData")

colnames(report_tech3)[3:13] <- c("Coal","Gas","Hydro","Nuclear","Solar|PV","Solar|CSP","Wind","Biomass","Battery","Oil","Geothermal")

report_tech3 <- report_tech3 %>% gather(3:13,key = "Tech",value = "Value") %>% 
  mutate(Year=as.integer(as.character(Year)))

cc_region <- ggplot()+
  geom_line(report_tech3 %>% filter(Tech!="Battery",Year>2015),mapping = aes(x=Year,y = Value,color=Region,group=interaction(Region,Tech)))+
  facet_wrap(~Tech,scales = "free")+
  labs(x="",y="Capital costs(US$2005/kW)",tag = "a")
cc_region

load(file = "data/capitalcosts.RData")
colnames(df3)[3:13] <- c("Coal","Gas","Hydro","Nuclear","Solar|PV","Solar|CSP","Wind","Biomass","Battery","Oil","Geothermal")

df3 <- df3 %>% gather(3:13,key = "Tech",value = "Value") %>% 
  #filter(Tech %in% unique(new_df$Tech)) %>% 
  mutate(Year=as.integer(as.character(Year)))

blah <- ggplot()+
  geom_line(df3 %>% filter(Year>2015,Tech!="Battery"),mapping = aes(x=Year,y=Value,color=Region,group=interaction(Tech,Region)))+
  # scale_colour_manual(values=myColors,aesthetics = "color")+
  labs(y="Capital costs [2020=1]",x="",tag = "b")+
    facet_wrap(~Tech,scales = "free")

blah



```

## Figure S15
```{r}

load(file = "data/onlyLP_1.RData")
# normalised gdp per capita
blah2 <- ggplot()+geom_line(only_LP %>% filter(Year>2015),mapping = aes(x=Year,y=1/Value,color=Region))+
  geom_line(only_LP %>% group_by(Year) %>% summarise(Value=mean(Value)) %>% filter(Year>2015),
            mapping = aes(x=Year,y=1/Value),color="black",linetype="dashed")+
  ggrepel::geom_text_repel(only_LP %>% filter(Year==2050),mapping = aes(x=2050,y=1/Value,label=Region,color=Region),size=2,show.legend = F)+
  labs(y="1/GDP per capita [2020=1]",x="")+
  coord_cartesian(ylim=c(0.2,1.4))+
  theme_bw()

# absolute gdp per capita
load(file = "data/onlyLP_2.RData")

blah3 <- ggplot()+geom_line(only_LP %>% filter(Year>2015),mapping = aes(x=Year,y=Value,color=Region),show.legend = F)+
   ggrepel::geom_text_repel(only_LP %>% filter(Year==2050),mapping = aes(x=2050,y=Value,label=Region,color=Region),size=2,show.legend = F)+
  labs(y="GDP per capita SSP2 (US$ 2005)",x="")+
  theme_bw()

gdp_plot <- ggarrange(blah3,blah2,labels = c("a","b"),legend = "none")
gdp_plot
```

## Figure S16
```{r}
# solar pv utility
a <- ggplot()+
  geom_line(x_own %>% filter(Activity!="Fuel_supply",Scenario=="Pol",Tech=="Solar|PV-utility",comb2!="no LP no capcosts"),mapping = aes(x=Year,y=Value,color=Region,group=Region))+
  facet_grid(Activity~comb2,scales = "free")+
  labs(x="",y="",subtitle =  "Wind onshore employment factors (FTE/MW)",tag = "a")
a

b <- ggplot()+
  geom_line(x_own %>% filter(Activity!="Fuel_supply",Scenario=="Pol",Tech=="Wind onshore",comb2!="no LP no capcosts"),mapping = aes(x=Year,y=Value,color=Region,group=Region))+
  facet_grid(Activity~comb2,scales = "free")+
  labs(x="",y="",subtitle =  "Wind onshore employment factors (FTE/MW)",tag = "b")
b



# Biomass
c <- ggplot()+
  geom_line(x_own %>% filter(Activity=="Fuel_supply",Activity!="OM",Scenario=="Pol",Tech=="Biomass",comb2!="no LP no capcosts"), mapping = aes(x=Year,y=Value,color=Region,group=Region))+
  facet_grid(Activity~comb2,scales = "free")+
  labs(x="",y="",subtitle = "Biomass fuel supply employment factors (FTE/PJ)",tag = "c")
c

# Coal
d <- ggplot()+
  geom_line(x_own %>% filter(Activity=="Fuel_supply",Activity!="OM",Scenario=="Pol",Tech=="Coal",comb2!="no LP no capcosts"), mapping = aes(x=Year,y=Value,color=Region,group=Region))+
  facet_grid(Activity~comb2,scales = "free")+
  labs(x="",y="",subtitle = "Biomass fuel supply employment factors (FTE/PJ)",tag = "c")
d


```

## Figure S17
```{r}
cap <-  df %>% filter(Variable=="Cap",comb=="static+static") %>%  
  group_by(Year,Scenario,comb2,Tech) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup() 


add_cap <- df %>% filter(Variable=="New Cap",comb=="static+static") %>%  
  group_by(Year,Scenario,comb2,Tech) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup() 

add_cap_plot <- ggplot()+
  geom_area(add_cap %>% filter(Year<2051,Year>2010), mapping = aes(x=as.factor(Year),y=Value,fill=Tech,group=interaction(Scenario,Tech)),stat = "identity")+
  labs(x="",y="New Capacity (GW)")+
  facet_grid(~Scenario)+
  scale_colour_manual(values=myColors, aesthetics = "fill")+
  theme_bw()
 

oa_cap <-ggplot()+
  geom_area(cap %>% filter(Year<2051,Year>2010), mapping = aes(x=as.factor(Year),y=Value,fill=Tech,group=interaction(Scenario,Tech)),stat = "identity")+
  labs(x="",y="Capacity (GW)")+
  facet_grid(~Scenario)+
  scale_colour_manual(values=myColors, aesthetics = "fill")+
  theme_bw()

production <-  df %>% filter(Variable=="Production",comb=="static+static",!is.na(Value)) %>%  
  group_by(Year,Scenario,comb2,Tech) %>% 
  summarise(Value=sum(Value)) %>% 
  ungroup()

oa_prod <-ggplot()+
  geom_area(production %>% filter(Year<2051,Year>2010),mapping = aes(x=as.factor(Year),y=Value,fill=Tech,group=interaction(Scenario,Tech)),stat = "identity")+
  labs(x="",y="Production (EJ)")+
  facet_grid(~Scenario)+
  scale_colour_manual(values=myColors, aesthetics = "fill")+
  theme_bw()

  arrange <- ggpubr::ggarrange(oa_cap,oa_prod,add_cap_plot,ncol = 1,legend = "right",common.legend = T,align = "v",labels=c("a","b","c"))
  arrange
```

## Figure S18
```{r}

load(file = "data/shrsubtech.RData")
ggplot()+ geom_line(shr,mapping = aes(x=Year,y = Value,color=Region,group=interaction(Region)))+
  facet_grid(Tech~.)+labs(y="",x="")+
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
        text = element_text(size=12))
```


## Figure S19
```{r}
activity <- df %>% filter(Variable=="Jobs",comb!="static+static") %>%  
  group_by(Year,Scenario,Activity,comb2) %>% 
   summarise(Value=sum(Value)) %>% 
                ungroup() %>% 
  spread(Activity,value = "Value") %>% 
  mutate(total=`CI`+`OM`+`Fuel_supply`+`Manf`) %>% 
  mutate(`C&I`=(`CI`/`total`),
         `O&M`=(`OM`/`total`),
         `Manufacturing`=(`Manf`/`total`),
          `Fuel supply`=(`Fuel_supply`/`total`)) %>% 
  select(1:3,9:12) %>% 
  gather(4:7,key = "Variable",value="Value")

# share of activity as percent of total jobs, comparison 2050 and 2020
  share_plot <- ggplot()+
  geom_point(activity %>% filter(Year==2050),mapping = aes(x=Variable,y=Value*100,color=comb2,shape=Scenario),size=3)+
  labs(y="Share of activity as % of total jobs",x="")+
  geom_point(activity %>% filter(Year==2020) %>% group_by(Scenario,comb2,Year,Variable) %>% summarise(Value=sum(Value)),mapping = aes(x=Variable,y=Value*100),size=3,shape=7)+
    #theme(axis.text.x = element_text(angle = 90))+
    coord_flip()
  share_plot
```

## Figure S20
```{r}
  # share of activity as percent of total jobs
  share_plot2 <- ggplot()+
    geom_line(activity %>% filter(Year>2015),mapping = aes(x=Year,y=Value,color=Variable,linetype=Scenario))+
    facet_wrap(.~comb2)+
    theme_bw()+
    theme(legend.position = "top")+
    labs(x="",y="Share of total (%)")
share_plot2
    
```

