---
title: "On the numerical inevitability of socialism"
author:
  - Ingram S. Jaccard:
      email: jaccard@pik-potsdam.de
      institute: [PIK]
      correspondence: false
  - Peter-Paul Pichler:
      email: pichler@pik-potsdam.de
      institute: [PIK]
      correspondence: false
  - Johannes Többen:
      email: toebben@pik-potsdam.de
      institute: [PIK]
      correspondence: false
  - Helga Weisz:
      email: weisz@pik-potsdam.de
      institute: [PIK, HU]
      correspondence: false
institute:
  - PIK: Social Metabolism and Impacts, Potsdam Institute for Climate Impact Research, Member of the Leibniz Association, PO Box 60 12 03, Potsdam, 14412, Germany
  - HU: Department of Cultural History & Theory and Department of Social Sciences, Humboldt University Berlin, Unter den Linden 6, Berlin, 10117, Germany
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: 
    bookdown::word_document2:
      fig_caption: yes
      reference_docx: "../templates/template.docx" # Insert path for the DOCX file
      pandoc_args:
      - --lua-filter=../templates/scholarly-metadata.lua
      - --lua-filter=../templates/author-info-blocks.lua
      - --lua-filter=../templates/pagebreak.lua
bibliography: references.bib
csl: "../templates/journal-of-archaeological-science.csl" # Insert path for the bib-style
abstract: |
  Text of abstract
keywords: |
  keyword 1; keyword 2; keyword 3
highlights: |
  These are the highlights. 
---

<!-- This is the format for text comments that will be ignored during renderings. Do not put R code in these comments because it will not be ignored. -->

<!-- With the following code you can access and display values from the yml header above. -->

Keywords: `r rmarkdown::metadata$keywords`

Highlights: `r rmarkdown::metadata$highlights`

<!-- The following code chunk defines some general settings how code chunks should behave. -->

```{r setup, echo = FALSE, include = FALSE, message = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  message = FALSE,
  echo = FALSE,
  comment = "#>",
  fig.path = "../figures/",
  dpi = 300
)

if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse,
               janitor,
               here,
               wbstats,
               ISOcodes,
               viridis,
               hrbrthemes,
               wesanderson,
               glue,
               ggridges,
               patchwork)

pal <- wes_palette("Cavalcanti1", 5, type = "discrete")
extrafont::loadfonts()

```

```{r libraries}

library(here)
```

```{r functions}

source(here("analysis", "r", "wrangler_functions.R"))

```

```{r load-data, include=FALSE}
# load data wrangling functions
source(here("analysis", "r", "wrangler_functions.R"))

## load result data for EU deciles
eu_q_count = 10

# summary countries aggregated by country quintiles and eu ntile
dat_country_summary_by_cquint_and_euntile = get_country_summary_by_cquint_and_euntile(eu_q_count)
# pivot to long format for plotting and attach readable indicator names
cols_ex = c("year", "iso2", "quint", "eu_q_rank")
pdat_country_summary_by_cquint_and_euntile =
  pivot_results_longer_adorn(dat_country_summary_by_cquint_and_euntile, cols_ex)

# summary of countries by EU quantile without sectoral resolution
dat_country_summary_by_eu_ntile = get_country_summary_by_eu_ntile(eu_q_count)
# pivot to long format for plotting and attach readable indicator names
cols_ex = c("year", "iso2", "eu_q_rank")
pdat_country_summary_by_eu_ntile = 
  pivot_results_longer_adorn(dat_country_summary_by_eu_ntile, cols_ex)

# summary of countries by country quintile with aggregate sectoral resolution
dat_sector_summary_by_country_quintile = get_sector_summary_by_country_quintile(eu_q_count)
# pivot to long format for plotting and attach readable indicator names
cols_ex = c("year", "iso2", "quint", "eu_q_rank", "sector_agg_id")
pdat_sector_summary_by_country_quintile =
  pivot_results_longer_adorn(dat_sector_summary_by_country_quintile, cols_ex)

# summary of eu ntile with aggregate sectoral resolution
dat_sector_summary_by_eu_ntile = get_sector_summary_by_eu_ntile(eu_q_count)
# pivot to long format for plotting and attach readable indicator names
cols_ex = c("year", "eu_q_rank", "sector_agg_id")
pdat_sector_summary_by_eu_ntile =
  pivot_results_longer_adorn(dat_sector_summary_by_eu_ntile, cols_ex)


```

<!-- The actual document text starts here: -->

# Introduction

Decarbonization scenarios that are compatible with the achievement of the Paris Accord to keep global warming well below 2°C above pre-industrial levels consider both the supply and the demand side in the necessary transformation of the energy system. On the supply side, economic and physical upper limits exist due to the assumptions of how much energy can be provided from renewable sources on the one hand, and how much CO2 removal infrastructure is used to compensate for remaining emissions from fossil fuels on the other. On the demand side [@creutzig_towards_2018] there are lower limits to how much energy is minimally required for a decent life [@grubler_low_2018 @millward-hopkins_providing_2020], depending on different assumptions about the available infrastructure of energy services, as well the prevalent social ideas about what constitutes a good life. Maximum possible energy supply and minimum necessary energy demand describe a space in which the simultaneous achievement of climate targets and a decent living for all depends on the distribution of available energy services among the population.

If this dual objective is taken seriously in European climate policy, then there are practical limits to how unequal the society of the future can be, which go beyond the purely political. The European Green Deal already recognizes that inequalities in incomes, energy consumption and greenhouse gas emissions lead to different responsibilities and capacities in achieving the emission savings targets, and includes proposals to increase equity and political acceptance. However, a limited energy supply creates an obvious, if rarely acknowledged, zero-sum game where energetic overconsumption by some has to be compensated by less consumption by others.

The average energy footprint of EU citizens was X GJ per capita in 2011 [oswald_large_2020] and the carbon footprint 8.2 tonnes CO2e per capita in 2007 [@ivanova_environmental_2016]. However, the differences in average energy and carbon footprints are large within and between different regions in the EU. Energy footprints ranged from X to Y GJ per capita in 2011 [@oswald_large_2020] and carbon footprints from below 2.5 tonnes CO2eq per capita to 55 tonnes CO2eq per capita in 2010 [@ivanova_unequal_2020]. Depending on the assumptions of different global mitigation scenarios, the average footprints need to be reduced to between 15.7 and 100 GJ per capita [@grubler_low_2018 @millward-hopkins_providing_2020] or 0.7 and 2.1 tCO2e per capita [@akenji_1.5-degree_2019] by 2050, respectively.

We assess under what conditions European energy inequality is compatible with the achievement of global climate goals and a decent standard of living following these steps. We first construct common European expenditure deciles based on national income stratified household expenditure data covering 30 European countries, further stratified by 5 consumption sectors. We then calculate average household GHG and energy footprints per European expenditure decile and consumption sector to explore the current structure of energy and carbon intensities across these categories. Based on these results, we use the current empirical per sector best technology to calculate a homogenized counterfactual European household energy demand distribution (and associated emissions) at current European consumption levels. We report energy and emissions savings per expenditure decile and country and relate the resulting energy demand to available supply across different global 1.5°C scenarios from the literature. Using assumptions on decent living energy demand and available energy supply from different 1.5°C scenarios show how the homogenized European energy demand distribution would need to be transformed (flattened) to conform to these constraints. We report exemplary implications for energy use in different expenditure deciles. Finally, we discuss implications for policy (GND, doughnut, carbon border adjustment mechanism for non-eu emissions).

# Materials and methods

We first decomposed national household final demand expenditure in the Environmentally-Extended Multi-Regional Input-Output (EE-MRIO) model EXIOBASE (version3, industry-by-industry) (ref), by income quintile, using European household budget survey (HBS) macro-data from EUROSTAT (ref). The EUROSTAT HBS publishes national data on mean consumption expenditure by income quintile (in purchasing power standard (PPS) euro) and the structure of consumption expenditure by income quintile and COICOP consumption category. We mapped the EXIOBASE sectors to one of the COICOP consumption categories (our mapping can be found in the SI), and used the relative shares of each COICOP consumption category between the income quintiles in the HBS to decompose the EXIOBASE national household final demand expenditure per sector by income quintile as well. We then multiplied this income-stratified EXIOBASE national household final demand expenditure by 'total' energy use and carbon intensities per EXIOBASE sector, calculated in EXIOBASE using standard input-output calculations, to estimate national household energy and carbon footprints stratified by income quintile.

The energy footprint is the gross total energy use energy extension in EXIOBASE, which converts final energy consumption in the IEA energy balance data from the territorial to residence principle following SEEA energy accounting (ref - Stadler et al.). The carbon footprint includes CO2, CH4, N2O, SF6, HFCs and PFCs, from combustion, non-combustion, agriculture and waste, but not land-use change. For both footprints, direct energy use and carbon emissions from households is included, with the total split between shelter, transport and manufactured goods using further data from EUROSTAT on this split.

Finally, we aggregated the data of 30 European countries with 5 income groups each into 10 European expenditure groups, to decompose the total European household energy and carbon footprint by European expenditure decile, ranking each national income group according to their mean consumption expenditure in PPS. We call these European expenditure deciles, although only countries with EUROSTAT data from 2005 to 2015 are included, which excludes Italy and Luxembourg, but includes the UK, Norway and Turkey.

We use households normalized by adult equivalent unit as the unit of analysis, following the EUROSTAT HBS. The adult equivalent units from EUROSTAT adjust for household size in different countries and income groups. As inequality measure through the study, we divide the average value of the population in the top decile by that of the bottom decile, a 10:10 ratio. For example, in expenditure, a 10:10 ratio of 5 means that adult equivalent units in the top decile spend 5 times more on average than those in the bottom decile. The data and procedures are described in detail in the supplementary information (SI).

*Still to add: Scenario sources we use. IIASA scenario database, IEA, DLE, maybe Boell.*

# Results

## Resource footprints are less unequal than expenditure levels

```{r ntiles-total}

p1 = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_fd_me") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000001,
            eu_ntile_name = first(eu_ntile_name)) %>%
  ggplot(aes(x=eu_ntile_name, y=value)) +
    geom_col(position = position_dodge(), fill=pal[1]) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Expenditure (trn€)") +
    theme(axis.text.x = element_text(angle = 90))

p2 = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_energy_use_tj") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000001,
            eu_ntile_name = first(eu_ntile_name)) %>%
  ggplot(aes(x=eu_ntile_name, y=value)) +
    geom_col(position = position_dodge(), fill=pal[1]) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Energy footprint (EJ)") +
    theme(axis.text.x = element_text(angle = 90))


p3 = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_co2eq_kg") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000000001,
            eu_ntile_name = first(eu_ntile_name)) %>%
  ggplot(aes(x=eu_ntile_name, y=value)) +
    geom_col(position = position_dodge(), fill=pal[1]) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Carbon footprint (MtCO2eq)") +
    theme(axis.text.x = element_text(angle = 90))


p_top = p1 + p2 + p3

```

```{r ntiles-intensity-violin}


p1 = dat_country_summary_by_eu_ntile %>%
  filter(year == 2015) %>%
  ggplot(aes(x=factor(eu_q_rank), y=pe_co2eq_kg)) +
  geom_violin(aes(weight=total_fd_me), fill=pal[1], color=pal[1], alpha=0.5) +
  geom_point( alpha=0.3) +
  geom_segment(data=dat_country_summary_by_eu_ntile %>%
                 filter(year == 2015) %>%
                 group_by(eu_q_rank) %>%
                 summarise(pe_co2eq_kg = weighted.mean(pe_co2eq_kg,total_fd_me)),
               aes(y=pe_co2eq_kg, yend=pe_co2eq_kg, x=eu_q_rank-0.3, xend=eu_q_rank+0.3), size=1.5) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Carbon intensity per expenditure (kgCO2eq/€)") +
    theme(axis.text.x = element_text(angle = 90))

p2 = dat_country_summary_by_eu_ntile %>%
  filter(year == 2015) %>%
  ggplot(aes(x=factor(eu_q_rank), y=pe_energy_use_mj)) +
  geom_violin(aes(weight=total_fd_me), fill=pal[1], color=pal[1], alpha=0.5) +
  geom_point( alpha=0.3) +
  geom_segment(data=dat_country_summary_by_eu_ntile %>%
                 filter(year == 2015) %>%
                 group_by(eu_q_rank) %>%
                 summarise(pe_energy_use_mj = weighted.mean(pe_energy_use_mj,total_fd_me)),
               aes(y=pe_energy_use_mj, yend=pe_energy_use_mj, x=eu_q_rank-0.3, xend=eu_q_rank+0.3), size=1.5) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Energy intensity per expenditure (MJ/€)") +
    theme(axis.text.x = element_text(angle = 90))

dat3 = dat_country_summary_by_eu_ntile %>%
  filter(year == 2015) %>%
  mutate(intensity_e_c = total_co2eq_kg*0.001/total_energy_use_tj)

p3 = dat3 %>%
  ggplot(aes(x=factor(eu_q_rank), y=intensity_e_c)) +
  geom_violin(aes(weight=total_energy_use_tj), fill=pal[1], color=pal[1], alpha=0.5) +
  geom_point( alpha=0.3) +
  geom_segment(data=dat3 %>%
                 filter(year == 2015) %>%
                 group_by(eu_q_rank) %>%
                 summarise(intensity_e_c = weighted.mean(intensity_e_c,total_energy_use_tj)),
               aes(y=intensity_e_c, yend=intensity_e_c, x=eu_q_rank-0.3, xend=eu_q_rank+0.3), size=1.5) +
    #theme_ipsum() +
    theme_minimal() +
    theme(text=element_text(family="Liberation Sans Narrow")) +
    labs(x="", y="Carbon intensity per energy (gCO2eq/TJ)") +
    theme(axis.text.x = element_text(angle = 90)) 


p_bottom = p2 + p1 + p3

#p3 & theme(plot.margin =  margin(1, 1, 1, 1, "mm"))
```

```{r , fig.width=12, fig.height=8}

a = p_top / p_bottom + plot_annotation(tag_levels = 'a') +
  plot_layout(guides = 'collect')  & 
  theme(plot.margin = unit(c(0.25,0.25,0.25,0.25), "cm"),
        legend.position = 'bottom',
        axis.title.y = element_text(size=13, hjust = 0.5),
        legend.text = element_text(size=12),
        legend.title = element_text(size=13))

ggsave(here("analysis", "figures", "figure1-test.pdf"))

```

```{r values-in-text1}

# values in text

## inequality
exp = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_fd_me") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000001,
            eu_ntile_name = first(eu_ntile_name))

exp_10_10 = round((exp %>% filter(eu_q_rank == 10))$value/(exp %>% filter(eu_q_rank == 1))$value,digits = 1)

energy = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_energy_use_tj") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000001,
            eu_ntile_name = first(eu_ntile_name))

energy_10_10 = round((energy %>% filter(eu_q_rank == 10))$value/(energy %>% filter(eu_q_rank == 1))$value,digits = 1)

co2eq = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015, 
         indicator == "total_co2eq_kg") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value)*0.000000001,
            eu_ntile_name = first(eu_ntile_name))

co2eq_10_10 = round((co2eq %>% filter(eu_q_rank == 10))$value/(co2eq %>% filter(eu_q_rank == 1))$value,digits = 1)

## total per decile

exp_bottom_decile = round((exp %>% filter(eu_q_rank == 1))$value, digits = 1)

exp_top_decile = round((exp %>% filter(eu_q_rank == 10))$value, digits = 1)

energy_bottom_decile = round((energy %>% filter(eu_q_rank == 1))$value, digits = 1)

energy_top_decile = round((energy %>% filter(eu_q_rank == 10))$value, digits = 1)

co2eq_bottom_decile = round((co2eq %>% filter(eu_q_rank == 1))$value, digits = 1)

co2eq_top_decile = round((co2eq %>% filter(eu_q_rank == 10))$value, digits = 1)


## per adult equivalent per decile

aeu = pdat_country_summary_by_eu_ntile %>%
  filter(year == 2015,
         indicator == "total_adult_eq") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value),
            eu_ntile_name = first(eu_ntile_name)) 

exp_pae = exp %>%
  rename(total_fd_me = value) %>%
  left_join(aeu, by = c("eu_q_rank", "eu_ntile_name")) %>%
  mutate(pae_fd_e = (total_fd_me/value)*1000000000000)

fd_pae_bottom_decile = round((exp_pae %>% filter(eu_q_rank == 1))$pae_fd_e, digits = 0)

fd_pae_top_decile = round((exp_pae %>% filter(eu_q_rank == 10))$pae_fd_e, digits = 0)

energy_pae = energy %>%
  rename(total_energy_use_tj = value) %>%
  left_join(aeu, by = c("eu_q_rank", "eu_ntile_name")) %>%
  mutate(pae_energy_use_gj = (total_energy_use_tj/value)*1000000000)

energy_pae_bottom_decile = round((energy_pae %>% filter(eu_q_rank == 1))$pae_energy_use_gj, digits = 1)

energy_pae_top_decile = round((energy_pae %>% filter(eu_q_rank == 10))$pae_energy_use_gj, digits = 1)

co2eq_pae = co2eq %>%
  rename(total_co2eq_kg = value) %>%
  left_join(aeu, by = c("eu_q_rank", "eu_ntile_name")) %>%
  mutate(pae_co2eq_t = (total_co2eq_kg/value)*1000000)

co2eq_pae_bottom_decile = round((co2eq_pae %>% filter(eu_q_rank == 1))$pae_co2eq_t, digits = 1)

co2eq_pae_top_decile = round((co2eq_pae %>% filter(eu_q_rank == 10))$pae_co2eq_t, digits = 1)


## intensities

mean_energy_intens = dat_country_summary_by_eu_ntile %>%
                 filter(year == 2015) %>%
                 group_by(eu_q_rank) %>%
                 summarise(pe_energy_use_mj = weighted.mean(pe_energy_use_mj,total_fd_me))

mean_energy_intens_bottom_decile = round((mean_energy_intens %>% filter(eu_q_rank == 1))$pe_energy_use_mj, digits = 1)

mean_energy_intens_top_decile = round((mean_energy_intens %>% filter(eu_q_rank == 10))$pe_energy_use_mj, digits = 1)

mean_co2eq_of_energy_intens = dat_country_summary_by_eu_ntile %>%
  filter(year == 2015) %>%
  mutate(intensity_e_c = total_co2eq_kg*0.001/total_energy_use_tj) %>%
  group_by(eu_q_rank) %>%
  summarise(intensity_e_c = weighted.mean(intensity_e_c,total_energy_use_tj))

mean_co2eq_of_energy_intens_bottom_decile = round((mean_co2eq_of_energy_intens %>% filter(eu_q_rank == 1))$intensity_e_c, digits = 1)

mean_co2eq_of_energy_intens_top_decile = round((mean_co2eq_of_energy_intens %>% filter(eu_q_rank == 10))$intensity_e_c, digits = 1)

```

Consumption-based indicators such as the energy and greenhouse gas footprint of households are largely determined by their spending levels. An inequality of household expenditures in a population therefore implies an inequality of their resource footprints. Figures 1a-c show European households by decile of expenditure and their associated resource footprints for GHGs and energy in 2015. The figures show that increasing expenditure generally translated into larger resource footprints, but that the inequality decreased from expenditure to energy to greenhouse gas emissions with 10:10 ratios (the top decile divided by the bottom decile) of `r exp_10_10`, `r energy_10_10` and `r co2eq_10_10`, respectively. Total expenditure ranged from `r exp_bottom_decile` trn€ to `r exp_top_decile` trn€ (or `r fd_pae_bottom_decile`€ to `r fd_pae_top_decile`€ per adult equivalent) across bottom and top decile, the energy footprint from `r energy_bottom_decile` EJ to `r energy_top_decile` EJ (or `r energy_pae_bottom_decile` GJ/ae to `r energy_pae_top_decile` GJ/ae), and the GHG footprint from `r co2eq_bottom_decile` MtCO2eq to `r co2eq_top_decile` MtCO2eq (or `r co2eq_pae_bottom_decile` tCO2eq/ae to `r co2eq_pae_top_decile` tCO2eq/ae). The reason for this is evident from figures 1d-f. Both the energy intensity measured as energy use per € expenditure (d) and the carbon intensity measured as GHGs per unit of energy use (f) gradually decrease from bottom to top expenditure decile. The average energy intensity of consumption decreased from `r mean_energy_intens_bottom_decile` MJ/€ in the bottom decile to less than half (`r mean_energy_intens_top_decile` MJ/€) in the top decile. Additionally, the GHG intensity of energy use was also higher in the bottom decile (`r mean_co2eq_of_energy_intens_bottom_decile` gCO2eq/TJ) compared to the top decile (`r mean_co2eq_of_energy_intens_top_decile` gCO2eq/TJ). There is a clear trend of decreasing intensities across expenditure deciles even though the variance in the lower deciles is much higher. The GHG intensity of consumption (figure 1e) combines the effects of the intensities of 1d and 1f. [*The higher GHG intensity of energy use is likely due to a larger share of emission intensive energy carriers in the energy system. The decreasing energy intensity per expenditure is due to either inefficient energy technologies or energy subsidies in poorer areas in Europe.*]

```{r figure1, out.width="98%", fig.cap="Expenditure and resource footprints and intensities across European expenditure deciles. Total expenditures (a), energy footprint (b), and GHG footprint (c) per decile. Energy intensity as energy footprint per expenditure (d), GHG intensity as GHG footprint per expenditure (e), and GHG intensity as GHG footprint per energy footprint (f)."}
knitr::include_graphics(here::here("analysis", "figures", "figure1-test.pdf"))
```

Figures 1d-e show that energy and GHG intensities are particularly high in the lower four deciles, while the higher deciles do not show large differences in weighted average resource intensity. The different intensities of household consumption across European expenditure deciles can be attributed to a combination of two plausible causes: first, if the the composition of consumption baskets systematically differs according to the level of household expenditure. Second, if resource intensity within individual consumption sectors systematically differs according to the level of household expenditure.

```{r , fig.width=8, fig.height=2}

pdat_basket = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), by="sector_agg_id") %>% 
  group_by(eu_q_rank) %>%
  mutate(value = total_fd_me/sum(total_fd_me)*100) %>%
  select(five_sectors, eu_q_rank, 
         value) %>%
  mutate(indicator = "Expenditure share (%)")

pdat_int_co2 = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), by="sector_agg_id") %>% 
  mutate(value = (total_co2_kg)/(total_fd_me*1000000)) %>%
  select(five_sectors, eu_q_rank, 
         value) %>%
  mutate(indicator = "GHG intensity (kgCO2/€)")

library(viridis)
pdat = pdat_int_co2 %>%
  bind_rows(pdat_basket)

a = ggplot(pdat, aes(x=value, y=five_sectors, color=eu_q_rank)) +
  #geom_point(shape=18, alpha=0.75) +
  geom_text(label="I", alpha=0.75, fontface="bold") +
  scale_color_viridis(option = "A", end = 0.8,
                      direction = -1, 
                      breaks = c(1, 5, 10), 
                      name="EU decile") +
  facet_wrap(~indicator, scales="free_x") +
  theme_minimal() +
  labs(x="", y="")+
  theme(text=element_text(size=13, family="Liberation Sans Narrow"))

ggsave(here("analysis", "figures", "figure2-test.pdf"))
```

```{r figure2, out.width="100%", fig.cap="Sectoral expenditure shares and GHG intensities of European expenditure deciles. Share of expenditure per final demand sector of total spending per decile in percent (a) and GHG intensity per final demand sector in kgCO2/€."}
knitr::include_graphics(here::here("analysis", "figures", "figure2-test.pdf"))
```

```{r values-in-text2}

exp_share_shelter_bottom_decile = round((pdat_basket %>% filter(eu_q_rank == 1, five_sectors == "shelter"))$value, digits = 1)

exp_share_shelter_top_decile = round((pdat_basket %>% filter(eu_q_rank == 10, five_sectors == "shelter"))$value, digits = 1)

int_co2_shelter_bottom_decile = round((pdat_int_co2 %>% filter(eu_q_rank == 1, five_sectors == "shelter"))$value, digits = 1)

int_co2_shelter_top_decile = round((pdat_int_co2 %>% filter(eu_q_rank == 10, five_sectors == "shelter"))$value, digits = 1)

exp_share_services_bottom_decile = round((pdat_basket %>% filter(eu_q_rank == 1, five_sectors == "services"))$value, digits = 1)

exp_share_services_top_decile = round((pdat_basket %>% filter(eu_q_rank == 10, five_sectors == "services"))$value, digits = 1)

```

Our data show that both of these factors play a role \@ref(fig:figure2). Poorer households on average, spend larger shares of their expenditure in the shelter sector. The bottom and top deciles spend an average of `r exp_share_shelter_bottom_decile`% and `r exp_share_shelter_top_decile`% of their household expenditures on shelter, respectively. Overall, with increasing expenditure decile, the shares of transport and services expenditures increase and the shares of shelter, food and manufactured goods decrease. At the same time, shelter is by far the most GHG intensive sector with the highest variance between expenditure deciles. In our sample, the intensity of all sectors decreases with expenditure level but the shelter sector stands out with a GHG intensity that is more than 3 times higher in the bottom decile (`r int_co2_shelter_bottom_decile` kgCO2eq/€) than in the top decile (`r int_co2_shelter_top_decile` kgCO2eq/€). Households in the top decile spend about `r exp_share_services_top_decile`% in the service sector that has the lowest GHG intensity, compared to `r exp_share_services_bottom_decile`% in the bottom decile [*wow that is high. correct?*]. Single country studies using MRIO models with national resolution can pick up on differences in consumption baskets but due to the homogeneous technology assumption cannot represent differences in technology between expenditure deciles.

The tendency that the emission intensity for direct energy consumption decreases with increasing affluence can be observed at the global level (XXX) between countries and also applies within Europe. In some of the Eastern European countries, between 80% and 100% of the population belong to the four lowest European expenditure deciles. This compares to less than 20% of the population in the richer European countries (Scandinavia, Germany, France, Austria, the Netherlands, Belgium, the UK, and Ireland). Note here that our analysis is based on average expenditure data from five income groups at the national level. This aggregation cuts off the lower and upper ends of the respective national expenditure distributions (Supplementary Note and Map).

The high resource intensities in the bottom four European expenditure deciles can be attributed in large part to inefficient domestic energy supplies for heating and electricity generation in Poland, Bulgaria, the Czech Republic, and Romania. Poland alone was responsible for about 40% of total coal combustion for heat production in Europe in 2015 and had a higher average GHG intensity per MJ of heat delivered than both Europe and the world (XXX). These differences in specific energy and emissions intensities in basic services sectors (especially shelter) account for the smaller inequality between expenditure deciles in terms of resource footprints compared to raw expenditures [*do we need to mention subsidies also?*].

*The consumption basket aspect has been extensively studied and mostly found to be intuitively true. This is a line of inquiry we do not currently pursue but I just remembered the analysis we did on this which is actually quite interesting: This common sense knowledge could be challenged because it is true mostly in western countries with high demand for heating and cooling and mobility both mostly fossil based and subsidized. In this case, necessities especially shelter (maybe and car based mobility (accessible to most)) have a higher intensity compared to "luxury spending" ie the average intensity of the international supply chain for manufactured goods etc.. It is not true in rich countries with high renewable energy shares (e.g. Norway) where the domestic energy system is more resource efficient than the international supply chain. It is possibly also not true in countries with low heating/cooling demand. We may want to check if that flips after applying the best technology transformation.*

## Inequality across final consumption sectors

```{r , fig.width=8, fig.height=5}

pdat = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), by="sector_agg_id") %>% 
  select(five_sectors, eu_q_rank, contains("pae_co2eq"), contains("pae_energy")) %>%
  pivot_longer(cols=-c(five_sectors, eu_q_rank), names_to="indicator", values_to="value") %>%
  mutate(indicator_type = if_else(str_detect(indicator, "co2eq"), 
                                  "tCO2eq per adult eq", 
                                  "Energy GJ per adult eq")) %>%
  filter(indicator != "pae_co2eq_t", 
         indicator != "pae_energy_use_gj")
  
  
pal <- wes_palette("Zissou1", 4, type = "discrete")
pal = pal[c(2,1,3,4)]
  
p1 = ggplot(pdat %>% filter(indicator_type == "tCO2eq per adult eq"), 
       aes(x=(eu_q_rank), y=value, fill=indicator)) +
  geom_col(position = position_stack()) +
  facet_wrap(~five_sectors, ncol = 5) +
  scale_fill_manual(values = pal, name="Location", labels=c("Direct", "Domestic", "EU", "non-EU")) +
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10), 
                     labels = c("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10")) +
  #theme_ipsum() +
  theme_minimal() +
  theme(text=element_text(family="Liberation Sans Narrow")) +
  labs(x="", y="CO2eq footprint tCO2eq per adult eq") +
  theme(legend.position = "bottom", 
          axis.text.x = element_text(angle = 90))


p2 = ggplot(pdat %>% filter(indicator_type == "Energy GJ per adult eq"), 
       aes(x=(eu_q_rank), y=value, fill=indicator)) +
  geom_col(position = position_stack()) +
  facet_wrap(~five_sectors, ncol = 5) +
  scale_fill_manual(values = pal, name="Location", labels=c("Direct", "Domestic", "EU", "non-EU")) +
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10), 
                     labels = c("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10")) +
  #theme_ipsum() +
  theme_minimal() +
  theme(text=element_text(family="Liberation Sans Narrow")) +
  labs(x="", y="Energy footprint GJ per adult eq") +
  theme(legend.position = "bottom", 
          axis.text.x = element_text(angle = 90))

a = p1 / p2 + plot_layout(guides = "collect") & theme(legend.position = 'bottom', 
                                                  plot.margin =  margin(1, 1, 1, 1, "mm"),
                                                  panel.spacing = unit(c(1, 1, 1, 1), "mm"))


hm = pdat %>% filter(indicator_type == "Energy GJ per adult eq") %>%
  group_by(eu_q_rank) %>%
  summarise(value = sum(value))

ggsave(here("analysis", "figures", "figure3-test.pdf"))
```

```{r values-in-text3}

co2eq_per_sector = pdat %>%
  filter(indicator_type == "tCO2eq per adult eq") %>%
  group_by(five_sectors, eu_q_rank) %>%
  summarise(value = sum(value))

transport_co2eq_10_10 = round((co2eq_per_sector %>% filter(eu_q_rank == 10, five_sectors == "transport"))$value/
                                (co2eq_per_sector %>% filter(eu_q_rank == 1, five_sectors == "transport"))$value,digits = 0)

man_goods_co2eq_10_10 = round((co2eq_per_sector %>% filter(eu_q_rank == 10, five_sectors == "manufactured goods"))$value/
                                (co2eq_per_sector %>% filter(eu_q_rank == 1, five_sectors == "manufactured goods"))$value,digits = 0)

services_co2eq_10_10 = round((co2eq_per_sector %>% filter(eu_q_rank == 10, five_sectors == "services"))$value/
                                (co2eq_per_sector %>% filter(eu_q_rank == 1, five_sectors == "services"))$value,digits = 1)

food_co2eq_10_10 = round((co2eq_per_sector %>% filter(eu_q_rank == 10, five_sectors == "food"))$value/
                                (co2eq_per_sector %>% filter(eu_q_rank == 1, five_sectors == "food"))$value,digits = 1)

energy_per_sector = pdat %>%
  filter(indicator_type == "Energy GJ per adult eq") %>%
  group_by(five_sectors, eu_q_rank) %>%
  summarise(value = sum(value))

transport_energy_10_10 = round((energy_per_sector %>% filter(eu_q_rank == 10, five_sectors == "transport"))$value/
                                (energy_per_sector %>% filter(eu_q_rank == 1, five_sectors == "transport"))$value,digits = 0)

man_goods_energy_10_10 = round((energy_per_sector %>% filter(eu_q_rank == 10, five_sectors == "manufactured goods"))$value/
                                (energy_per_sector %>% filter(eu_q_rank == 1, five_sectors == "manufactured goods"))$value,digits = 0)

services_energy_10_10 = round((energy_per_sector %>% filter(eu_q_rank == 10, five_sectors == "services"))$value/
                                (energy_per_sector %>% filter(eu_q_rank == 1, five_sectors == "services"))$value,digits = 1)

food_energy_10_10 = round((energy_per_sector %>% filter(eu_q_rank == 10, five_sectors == "food"))$value/
                                (energy_per_sector %>% filter(eu_q_rank == 1, five_sectors == "food"))$value,digits = 1)

```

In absolute terms, the various final consumption sectors contribute very differently to the total resource footprint of households (Figure 3). On average, shelter and transport are the two largest sectors, accounting for nearly two thirds of both resource footprints. However, there are big differences between the sectors when looking at the respective contributions in the expenditure quantiles. For shelter there is almost no difference (neither in GHG nor in energy footprint). Especially the lower four expenditure deciles have high GHG emissions, which can be explained by the extreme differences in resource intensity shown in Figure 2. Transport was the most unequal sector, with resource footprints `r transport_energy_10_10` times higher in the top decile compared to the bottom deciles (corroborating findings in [@ivanova_quantifying_2020] and [@oswald_large_2020]). Manufactured goods was the second most unequal consumption category (10:10 ratios around `r man_goods_energy_10_10` for both footprints), followed by services (10:10 ratios of `r services_co2eq_10_10` for GHGs and `r services_energy_10_10` for energy) and then food (10:10 ratios of `r food_energy_10_10` for both footprints).

```{r figure3, out.width="100%", fig.cap="Energy and GHG footprints by final demand sector and European expenditure decile in 2015 further broken down by emission source location."}
knitr::include_graphics(here::here("analysis", "figures", "figure3-test.pdf"))
```

```{r values-in-text4}

co2eq_per_source = pdat %>%
  filter(indicator_type == "tCO2eq per adult eq") %>%
  group_by(five_sectors, indicator) %>%
  summarise(value = sum(value)) %>%
  mutate(share = value/sum(value))

shelter_co2eq_direct = round(((co2eq_per_source %>% filter(five_sectors == "shelter", 
                                                          indicator == "pae_co2eq_direct_t"))$share)*100, digits = 0)

energy_per_source = pdat %>%
  filter(indicator_type == "Energy GJ per adult eq") %>%
  group_by(five_sectors, indicator) %>%
  summarise(value = sum(value)) %>%
  mutate(share = value/sum(value))

shelter_energy_direct = round(((energy_per_source %>% filter(five_sectors == "shelter", 
                                                          indicator == "pae_energy_use_direct_gj"))$share)*100, digits = 0)

```

[*The following paragraph needs an intro and polish, not clear at the moment why we say this. Maybe only relevant if we pick up reduction options of non-EU emissions in dscussion.*] The shelter footprint was almost entirely domestic, with `r shelter_co2eq_direct`/`r shelter_energy_direct`% coming from direct household emissions/energy use for heating and cooling, and the rest embedded primarily along the domestic supply chain. The transport footprint was just under 2/3rds domestic. The majority of the transport footprint, above 60%, came from vehicle fuel, either burned directly or indirectly embedded along its supply chain. More than half of the transport footprint's foreign 1/3rd came from outside Europe. The manufactured goods footprint was mostly non-European, while services and food were both around half domestic.

# Counterfactual: a 1.5°C compatible Europe

Global 1.5°C compatible decarbonisation scenarios achieve a similar climate outcome with different assumptions about the transformation of energy supply and demand, from renewable capacity, deployment of carbon-capture-and-storage (CCS), and socio-technological demand transformation.

[*Alternative to converting in the following text between per capita and per adult, we could convert scenarios to rough per adult equvialents and discuss differences across deciles in supplement*]

[*maybe table with scenario properties*]

The various global supply side scenarios (SSP1-1.9, SSP2-1.9, GEA efficiency) envisage total EU (*or our sample*) energy consumption falling from the current X EJ to X-Y EJ by 2030 (or 2050), equivalent to a per household reduction from a current average of 250 GJ to X-Y GJ per adult equivalent. The differences in energy consumption in 2050 in the scenarios reflect different model assumptions about the rate of expansion of renewable energy and CCS capacity. Most/all of these scenarios rely on substantial amounts of CCS (*starting from when?*) which is still a fairly speculative technology and we therefore interpret them as ranges for the upper limits of 1.5°C-compatible energy supply.

It is even more difficult to determine a lower limit for the minimum amount of energy needed for a decent life. This depends strongly on the one hand on the prevalent socio-cultural idea of what constitutes a decent life, and on the other hand, perhaps even more strongly, on the physical infrastructure available to satisfy human needs/to deliver on this life [*dont want a 'needs' debate with you Helga, just didnt know how to say this differently.*]. The two (*or three with Boell*) global demand side scenarios (LED, DLE) that attempt to define such a limit conclude that, in principle, a very low energy footprint (between 16-53 GJ per capita, or X-Y, translated to household adult equivalents) could be sufficient. However, these scenarios rely on socio-technological transformations on a scale that, especially at the lower end, far exceeds the current political discourse on the subject. All two/three scenarios are 1.5°C compatible without resorting to any CCS but they all implicitly (LED) or explicitly (DLE) assume near complete equality of consumption across the population. To put these low energy demand numbers in perspective, the average energy footprint in our sample is about a factor 5 above the high estimate (250 MJ/aeq). Households in the first European expenditure decile had an energy footprint of 130 GJ per adult equivalent (*give rough per capita*) in 2015 even though they fell almost entirely within the Eurostat definition of severe material deprivation.

[*I struggle to separate between energy efficiency in purely technological terms, and energy efficiency of the energy service. This is relevant for the transformation we apply. Do we assume the efficiency differences are only due to inefficient energy carriers and transformation losses, or do we assume this is also due to differences in the demand/provision of energy services, e.g. more rural and car dependent. It would be easier if we could argue the former, which I will do for now.*]

Based on these two constraints, the upper limit on the supply side and the lower limit on the demand side, it is possible to make a generalized estimate of how much inequality in the distribution of energy consumption is numerically possible, if at the same time global warming is to be kept below 1.5°C above pre-industrial levels and a good life for all is to be made possible. Before we can make this evaluation, we must take into account the existing large differences in the technological efficiency of energy provision (Figure 2). Since the European expenditure deciles discussed here include large population groups (\~X persons/households) with different demand structures for energy services (urban/rural, demographic, climatic), we assume that the variation in energy intensity across deciles is largely due to technological efficiency. These differences will be adjusted in the next step.

## Current empirical best technology per sector

```{r}
pal <- wes_palette("Zissou1", 4, type = "discrete")
pal = pal[c(2,1,3,4)]

pdat_int_energy = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), 
            by="sector_agg_id") %>% 
  mutate(intensity_energy = (total_energy_use_tj)/(total_fd_me)) %>%
  select(five_sectors, eu_q_rank, 
         intensity_energy) %>%
  filter(eu_q_rank == 10) %>%
  select(-eu_q_rank)

pdat_final_demand = get_sector_summary_by_eu_ntile_direct(eu_q_count) %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), 
            by="sector_agg_id") %>%
  left_join(pdat_int_energy, by="five_sectors") %>%
  mutate(total_energy_use_tj_new = (total_fd_me)*intensity_energy) %>%
  mutate(total_energy_use_tj_diff = total_energy_use_tj-total_energy_use_tj_new) %>%
  select(five_sectors, eu_q_rank, 
         total_energy_use_tj_diff, total_energy_use_tj_new) %>%
  group_by(eu_q_rank) %>%
  summarise(total_energy_use_tj_new = sum(total_energy_use_tj_new)*0.000001,
            total_energy_use_tj_diff = sum(total_energy_use_tj_diff)*0.000001) %>%
  pivot_longer(-c(eu_q_rank), names_to = "indicator", values_to = "value")


p1 = ggplot(pdat_final_demand, aes(x=eu_q_rank, y=value, fill=indicator, alpha=indicator)) +
  geom_col(position = position_stack()) +
  scale_fill_manual(values=c(pal[1], pal[2]), 
                    labels=c("2015", "Best technology"), name="Energy\nfootprint") +
  scale_alpha_manual(values=c(0.3,1),labels=c("2015", "Best technology"), name="Energy\nfootprint")+
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10), 
                     labels = c("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10")) +
  labs(y="Energy footprint (EJ)", x="") +
  theme_minimal() +
  coord_flip() +
  theme(legend.position="bottom")

```

```{r}

pdat_energy_country = get_sector_summary_by_country_quintile_direct() %>%
  ungroup() %>%
  filter(year==2015) %>%
  left_join(read_csv(here("analysis/data/derived/sectors_agg_method1_ixi.csv")), 
            by="sector_agg_id") %>%
  left_join(pdat_int_energy, by="five_sectors") %>%
  mutate(total_energy_use_tj_new = (total_fd_me)*intensity_energy) %>%
  #mutate(total_energy_use_tj_save = total_energy_use_tj_new/total_energy_use_tj*100) %>%
  select(iso2, 
         total_energy_use_tj_new, total_energy_use_tj) %>%
  group_by(iso2) %>%
  summarise(total_energy_use_tj_save = 100 - sum(total_energy_use_tj_new)/sum(total_energy_use_tj)*100)

```

```{r include=FALSE}

library(rworldmap)
library(ggthemes)



df_country_mean = pdat_energy_country %>%
  mutate(iso2 = if_else(iso2 == "EL", "GR", iso2)) %>%
  mutate(iso2 = if_else(iso2 == "UK", "GB", iso2)) %>%
  left_join(ISO_3166_1 %>% select(iso2 = Alpha_2, iso3 = Alpha_3), by="iso2")


quantile_rank_map = joinCountryData2Map(df_country_mean, 
                                        joinCode = "ISO_A3", 
                                        nameJoinColumn = "iso3")
quantile_rank_map_poly = fortify(quantile_rank_map) #extract polygons 

quantile_rank_map_poly = merge(quantile_rank_map_poly, quantile_rank_map@data, by.x="id", by.y="ADMIN", all.x=T)
quantile_rank_map_poly = quantile_rank_map_poly %>% arrange(id, order)

```

```{r dle-country, fig.width=8}
map = ggplot() + 
  geom_polygon(data = quantile_rank_map_poly, aes(long, lat, group = group), color="black") +
  geom_polygon(data = quantile_rank_map_poly, aes(long, lat, group = group, 
                                        fill=total_energy_use_tj_save)) + 
  #scale_fill_gradient(name="Mean decile \nrank", low="skyblue", high = "skyblue4", na.value = "#EEEEEE") +
  scale_fill_viridis(direction = -1, discrete = F, na.value = "white", name="Energy\nsavings (%)") +
  theme_map() +
  labs(x="",y="")+
  coord_map("bonne", lat0 = 50,xlim = c(-9, 40), ylim = c(38, 68), clip="on") +
  theme(legend.position = c(0.85, 0.6))
  
```

```{r fig.height=7, fig.width=11}

a = p1 + map + plot_annotation(tag_levels = 'a') +
  theme(plot.margin = unit(c(0.25,0.25,0.25,0.25), "cm"),
        legend.position = 'bottom',
        axis.title.y = element_text(size=13, hjust = 0.5),
        legend.text = element_text(size=12),
        legend.title = element_text(size=13))

ggsave(here("analysis", "figures", "figure4-test.pdf"))
```

```{r figure4, out.width="100%", fig.cap="Energy savings through sectoral best current technology by expenditure deciles a) and country b)."}
knitr::include_graphics(here::here("analysis", "figures", "figure4-test.pdf"))
```

Our results show that in 2015, rich people in rich countries had access to the most energy-efficient energy services across all final demand sectors (Figure 2b [*todo currently figure shows only GHG*]). Since we are interested in the numerically possible inequality in the distribution of actual consumption of goods and services in the next section, these efficiency differences must first be adjusted. In practice, this corresponds, for example, to the need for large-scale investments in the technical efficiency of heat, electricity and hot water supply, especially in Eastern Europe. Figure 4 shows the energy footprint savings per decile (Fig. 4a) that would have occurred in 2015 if all deciles had the same efficiency per final demand sector as the 10th decile. Around 17 EJ would have been saved in total, and the energy footprint of the first decile would have been nearly half its 2015 value. Fig. 4b shows saved energy per country, with Eastern European countries especially saving large proportions of their 2015 footprint, over 60% for Bulgaria and Estonia for example.

Points to hit: - Improving energy efficiency is the most politically uncontroversial step towards mitigation targets. The EU has a bunch of policies for that, old and new. The GD has a transition fund to pay for this for poorer countries, sort of.

## Inequality in a 1.5°C compatible Europe

```{r}

df_energy_deciles = read_csv(here("analysis/data/raw/energy_figure_data.csv")) 

ineq_curr = df_energy_deciles$pae_energy_use_gj[10]/df_energy_deciles$pae_energy_use_gj[1]

```

```{r}

library(readxl)

df_scenario_info = read_excel(here("analysis/data/raw/scenarios.xlsx"), sheet="overview") %>%
  select(scenario, fe_gj_aeu = final_energy_gj_per_aeu_2050,
         ccs_required = primary_energy_fossil_w_ccs2050_ej,
         description) %>%
  arrange(fe_gj_aeu) %>%
  mutate(fe_gj_aeu = round(fe_gj_aeu),
         ccs_required = round(ccs_required)) 

mea = c(min(df_scenario_info$fe_gj_aeu),max(df_scenario_info$fe_gj_aeu))
mer = c(min(df_scenario_info$fe_gj_aeu),53)

c_mean_mea = round((27+mea[2])/2)
c_mean_mer = round((mer[1]+mer[2])/2)

```

```{r , fig.width=7, fig.height=5.5}

round_by = 10

df_all = readRDS(here("analysis/data/raw/scenarios_fine.rds")) %>%
  filter(eu_q_rank %in% c(1,10)) %>%
  group_by(v_mean, v_first) %>%
  summarise(ratio = last(scaled)/first(scaled)) %>%
  mutate(bin_ratio = if_else((ratio*100)%%round_by > round_by*0.5, 
                             ratio*100+(round_by-(ratio*100)%%round_by),
                             ratio*100-(ratio*100)%%round_by)) %>%
  group_by(bin_ratio, v_first) %>%
  summarise(v_mean = mean(v_mean)) %>%
  mutate(bin_ratio = bin_ratio*0.01)

df_scenario = df_all %>%
  filter(v_mean %in% df_scenario_info$fe_gj_aeu) %>%
  left_join(df_scenario_info, by=c("v_mean"="fe_gj_aeu"))

library(wesanderson)

a = df_all %>%
  ggplot(aes(x=v_first, y=bin_ratio, fill=v_mean)) +
  geom_tile() +
  geom_hline(yintercept = ineq_curr, alpha=0.8, color="grey", linetype=2) +
  geom_line(data=df_scenario, aes(color=scenario, group=scenario)) +
  annotate(geom="text", x=max(df_all$v_first)-5.7,y=ineq_curr+0.6,label = "current 10:10 ratio") +
  #scale_fill_viridis("Mean energy\navailable") +
  scale_fill_gradient("Mean energy\navailable",
                      low=wes_palette("Chevalier1")[3], 
                      high = wes_palette("Rushmore1")[4]) +
  scale_color_manual(values=wes_palette("Darjeeling1")) +
  theme_minimal() +
  labs(x="Minimum energy requirement (GJ/aeu)", y="max inequality (10:10 ratio)")+
  theme(text=element_text(family="Liberation Sans Narrow"))# +
  #theme_ipsum()

ggsave(here("analysis", "figures", "figure5-test.pdf"))
```

Based on this counterfactual distribution of the energy footprint using homogeneous supply technologies, we can now scale down energy consumption across European expenditure deciles to meet supply constraints and, where necessary, "squeeze" the distribution to not undershoot minimum demand constraints in any decile. This means that, based on the current empirical distribution, for each value combination of supply and minimum necessary demand, the maximum permissible inequality can be calculated as a 10:10 ratio (Figure \@ref(fig:figure5). [*Ref to formula*]

Starting at the low end of energy supply, both (or all three with Boell) the DLE and LED scenarios satisfy energy demand without resorting to CCS technologies. The DLE scenario explicitly envisions absolute global equality (10:10 ratio of 1) in consumption, except for small differences in required energy consumption based on climatic and demographic factors, as well as differences in population density. The LED scenario does not explicitly discuss distributional aspects beyond giving different final energy consumption values for the Global North (53GJ/cap) and the Global South (27GJ/cap). However, due to the bottom-up construction of this demand scenario, these values can be interpreted as estimates for the minimum required energy demand. [*space permitting, give examples of the rather extreme nature of demand interventions here or in in scenario description/table above*]

The descriptions of the energy supply scenarios do not include specific details about how the energy footprints are distributed within the population. The energy savings here are achieved primarily through efficiency improvements, and perhaps also generally assumed demand reductions [*I actually know nothing about these scenarios, how do they achieve the reduction, and is energy demand actually resolved by country maybe?*]. However, Figure \@ref(fig:figure5) makes it clear that even with ambitious demand reductions, as in the LED scenario, a large reduction in inequality between the European expenditure quantiles is required.

At current inequality levels, only the two scenarios with heavy CCS deployment and GEA efficiency are possible if we assume extremely low minimum energy requirements (below 27 GJ/cap). This 27 GJ/capita is the value the low-energy demand (LED) scenario gives for the global South in 2050. If we use the value given for the global North at 53 GJ/cap (with strong demand side measures) then inequality would need to be drastically reduced, the 10:10 ratio more than halved, in all scenarios (including those with CCS deployment).

[*Figure supplement: show country map with energy reductions resulting from SSPx supply and LED demand*]

Mini-conclusion: It is not enough to maximise supply and minimise demand. To hit targets, inequality needs to dramatically reduce under all realistic scenarios.

```{r figure5, out.width="70%", fig.align="center", fig.cap="Dings. in Figure 5, all deciles have 'best technology' already"}
knitr::include_graphics(here::here("analysis", "figures", "figure5-test.pdf"))
```

# Conclusions

Measuring carbon-energy inequality is important for assigning responsibility for climate change. At a global, regional, and within-country level, energy consumption and carbon emissions can be highly unequal across income groups. The reduction of carbon-energy inequality is not a meaningful goal by itself, however. With more nuance on carbon-energy inequality, when carbon-energy intensities of income groups can be estimated using information on different consumption baskets and technologies, we have seen that in Europe, just bringing carbon-energy intensities of all income groups in line with the top group would reduce the carbon-energy footprint but *increase* carbon-energy inequality. That lower-income groups tend to have higher carbon-energy intensities is an important finding from the environmental Kuznet's curve literature [@berthe_mechanisms_2015 @scruggs_political_1998]. We find that this is the case for Europe as a whole (although not necessarily within each European country) [@sommer_carbon_2017]. Responsibility for climate change focuses on aggregate carbon-energy inequality, and thus tends to focus on reducing over-consumption at the top. Without differences in intensity included, where/what to target: aggregate consumption a problem at top, not at bottom, etc. 

Understanding this relationship is important towards achieving two potentially conflicting goals in Europe: carbon-energy footprint reduction and providing minimum energy use for decent living to everyone. At a global level, achieving sweeping poverty reduction in many regions of the world could put at risk hitting global climate targets (Hubacek). In the European context, although less unequal than the globe as a whole, lower-income groups will look to increase income, consumption, energy use, and carbon emissions will increase if more efficient and cleaner technology is not adopted at the appropriate rate. Achieving an average per capita energy use and carbon footprint in Europe in scenarios that reach the Paris agreement goals, means either doing so at current inequality levels and keeping lower-income groups near or below minimum energy use levels for decent living, or reducing economic inequality. We have shown that achieving both scenario targets and minimum energy levels likely requires reduction in economic inequality (consumption inequality reduction measures in Europe) coupled with the appropriate targeted climate-energy measures for the various income groups and countries (expand on how it relates to 1st paragraph).   

Refs to add:

demand side solution:

Royston, S., Selby, J. & Shove, E. Invisible energy policies: A new agenda for energy demand reduction. *Energy Policy* **123**, 127--135 (2018).

reduction in demand

Alfredsson, E. *et al.* Why achieving the Paris Agreement requires reduced overall consumption and production. *Sustainability: Science, Practice and Policy* **14**, 1--5 (2018).

# Acknowledgements

<!-- The following line inserts a page break  -->

\newpage

# References

<!-- The following line ensures the references appear here for the MS Word or HTML output files, rather than right at the end of the document (this will not work for PDF files):  -->

::: {#refs}
:::

\newpage

### Colophon

This report was generated on `r Sys.time()` using the following computational environment and dependencies:

```{r colophon, cache = FALSE}
# which R packages and versions?
if ("devtools" %in% installed.packages()) devtools::session_info()
```

The current Git commit details are:

```{r}
# what commit is this file at? 
if ("git2r" %in% installed.packages() & git2r::in_repository(path = ".")) git2r::repository(here::here())  
```
