Commit 3d85473d authored by Thomas Brand's avatar Thomas Brand
Browse files

Add electricity consumption in France post.

parent cc50498c
Pipeline #200764 canceled with stage
---
Title: Comparing 1st & 2nd lockdown using electricity consumption in France
date: 2020-12-8
Category: Data
Tags: DBnomics, database, R
Slug: electricity-conso-france
Authors: Thomas Brand
Summary: By using high-frequency data on electricity consumption in france, the impact of the second lockdown seems to have been less severe, especially for large companies.
Download: https://git.nomics.world/macro/macro.nomics.world/tree/master/content/elec-conso-france
output: html_document
---
```{r, echo=FALSE}
if (!"pacman" %in% installed.packages()[,"Package"])
install.packages("pacman", repos='http://cran.r-project.org')
pacman::p_load(tidyverse,rdbnomics,lubridate,zoo,ghibli,gghighlight,
gridExtra,grid,RcppRoll,knitr)
opts_chunk$set(message=FALSE, warning=FALSE, cache=FALSE, echo=FALSE, fig.align="center",fig.width=7,fig.height=6)
```
```{r}
#https://data.enedis.fr/explore/dataset/bilan-electrique-jour/information/
pme <- rdb("ENEDIS/ELECTRICITY_BALANCE/Profiled_SME_SMI_consumption.FRA.PROFILED_SME_SMI_CONSUMPTION.ALL.ALL.D")
resid <- rdb("ENEDIS/ELECTRICITY_BALANCE/Profiled_residential_consumption.FRA.PROFILED_RESIDENTIAL_CONSUMPTION.ALL.ALL.D")
hva <- rdb("ENEDIS/ELECTRICITY_BALANCE/Total_HVA_consumption.FRA.TOTAL_HVA_CONSUMPTION.ALL.ALL.D")
conso <- rdb("ENEDIS/ELECTRICITY_BALANCE/Total_consumption.FRA.TOTAL_CONSUMPTION.ALL.ALL.D")
temp <- rdb("ENEDIS/ELECTRICITY_BALANCE/Smoothed_realized_temperature.FRA.ALL.ALL.SMOOTHED_REALIZED_TEMPERATURE.D")
```
The health and economic crisis is of unprecedented scale and speed. To measure it, high frequency data are used, complementary to traditional data. We focus on electricity consumption from ENEDIS data, available on <a href="https://db.nomics.world/" target="_blank">DBnomics</a>, through the <a href="https://cran.r-project.org/web/packages/rdbnomics/index.html" target="_blank">rdbnomics</a> package. All the following code is written in R, thanks to the [@Rct16] and the [@RStu16].
```{r}
elec <-
bind_rows(pme,resid,hva,conso,temp) %>%
select(period,value,var=cons) %>%
group_by(var) %>%
mutate(value=roll_mean(value,7,align = "right",fill = NA)) %>%
mutate(value=as.numeric(value)/1e+09,
var=case_when(var=="PROFILED_RESIDENTIAL_CONSUMPTION" ~ "Residential",
var=="PROFILED_SME_SMI_CONSUMPTION" ~ "Small and medium enterprises",
var=="TOTAL_HVA_CONSUMPTION" ~ "Large enterprises",
var=="TOTAL_CONSUMPTION" ~ "Total consumption",
var=="ALL" ~ "Average temperature")) %>%
filter(period>="2016-01-01") %>%
separate(period,c("year","month_day"),sep="-",extra="merge")
elec_mean <-
elec %>%
filter(year != "2020") %>%
group_by(var,month_day) %>%
summarise(value=mean(value)) %>%
mutate(year="average \n2016-2019")
elec2 <-
bind_rows(elec,elec_mean) %>%
filter(month_day>="03-01",
month_day<="11-30")
subtitle_vec <- "in gigawatt, 7-day moving average"
title_total_vec <- "Total electricity consumption in France"
title_client_vec <- "Electricity consumption by customer category in France"
breaks_vec <- c("01-01","02-01","03-01","04-01","05-01","06-01","07-01","08-01","09-01","10-01","11-01","12-01")
labels_vec <- c("01-01"="Jan.","02-01"="Feb.","03-01"="Mar.","04-01"="Apr.","05-01"="May","06-01"="June",
"07-01"="July","08-01"="Aug.","09-01"="Sept.","10-01"="Oct.","11-01"="Nov.","12-01"="Dec.")
my_theme <-
theme_minimal()+
theme(legend.title = element_blank(),
legend.key = element_blank(),
legend.background = element_blank(),
plot.title=element_text(size=18,hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
axis.text = element_text(size = 13),
legend.text = element_text(size=10))
```
```{r}
ggplot(filter(elec2,var=="Total consumption"),
aes(month_day,value,colour=year,group=year))+
geom_line(size=1)+
scale_y_continuous(labels = scales::number_format(accuracy = 1))+
scale_x_discrete(breaks=breaks_vec,
labels=labels_vec)+
scale_color_manual(values=ghibli_palette("MononokeMedium"))+
gghighlight(year != "average \n2016-2019",
use_direct_label = F,
unhighlighted_params = list(colour="transparent"))+
my_theme+
theme(legend.position = c(0.85,0.75))+
labs(title=title_total_vec,
subtitle = subtitle_vec,
x=NULL,y=NULL)
#ggsave("elec_total_1.png",width = 8.5,height=7)
```
```{r}
ggplot(filter(elec2,var=="Total consumption"),
aes(month_day,value,colour=year,group=year))+
geom_line(size=1)+
scale_y_continuous(labels = scales::number_format(accuracy = 1))+
scale_x_discrete(breaks=breaks_vec,
labels=labels_vec)+
scale_color_manual(values=ghibli_palette("MononokeMedium")[5:1])+
gghighlight(year %in% c("average \n2016-2019","2020"),
use_direct_label = F,
unhighlighted_params = list(colour="transparent"))+
my_theme+
theme(legend.position = c(0.88,0.64))+
labs(title=title_total_vec,
subtitle = subtitle_vec,
x=NULL,y=NULL)
#ggsave("elec_total_2.png",width = 8.5,height=7)
```
Data shows under-consumption of electricity in the spring and over-consumption of electricity in the fall of 2020.
```{r}
figures <-
elec2 %>%
filter(var=="Total consumption",
year %in% c("2020","average \n2016-2019")) %>%
spread(year,value) %>%
mutate(min=pmin(`2020`,`average \n2016-2019`),
max=pmax(`2020`,`average \n2016-2019`),
above=`2020`>=`average \n2016-2019`,
changed = is.na(lag(above)) | lag(above) != above,
section_id = cumsum(changed),
diff=`2020`-`average \n2016-2019`)
sum <-
figures %>%
filter(month_day<="10-31") %>%
group_by(above) %>%
summarise(sum=sum(diff))
plot_elec_total_3 <- ggplot(filter(elec2,var=="Total consumption"),
aes(month_day,value,colour=year,group=year))+
geom_line(size=1)+
scale_y_continuous(labels = scales::number_format(accuracy = 1))+
scale_x_discrete(breaks=breaks_vec,
labels=labels_vec)+
scale_color_manual(values=ghibli_palette("MononokeMedium")[5:1])+
gghighlight(year %in% c("average \n2016-2019","2020"),
use_direct_label = F,
unhighlighted_params = list(colour="transparent"))+
geom_ribbon(data=filter(figures,above==FALSE),aes(x=month_day,ymin=min,ymax=max,group=section_id),fill="#06141FFF",alpha=0.2,inherit.aes = F)+
geom_ribbon(data=filter(figures,above==TRUE),aes(x=month_day,ymin=min,ymax=max,group=section_id),fill="#CD4F38FF",alpha=0.2,inherit.aes = F)+
annotate("text",x="05-10",y=45,label="sum of cons. < \naverage = -438\n(Mar.-July)")+
annotate("text",x="09-10",y=45,label="sum of cons. > \naverage = 215\n(Aug.-Oct.)")+
my_theme+
theme(legend.position = c(0.88,0.64))+
labs(title=title_total_vec,
subtitle = subtitle_vec,
x=NULL,y=NULL)
plot_elec_total_3
#ggsave("elec_total_3.png",plot=plot_elec_3,width = 8.5,height=7)
```
But variations in electricity consumption seem to be correlated with temperatures variations.
```{r}
temp2 <-
elec2 %>%
filter(var=="Average temperature",
year %in% c("2020","average \n2016-2019")) %>%
mutate(value=value*1e+09)
figures <-
temp2 %>%
spread(year,value) %>%
mutate(min=pmin(`2020`,`average \n2016-2019`),
max=pmax(`2020`,`average \n2016-2019`),
above=`2020`>=`average \n2016-2019`,
changed = is.na(lag(above)) | lag(above) != above,
section_id = cumsum(changed),
diff=`2020`-`average \n2016-2019`) %>%
ungroup()
moy_spread_mar_july <-
figures %>%
filter(month_day<="07-31") %>%
select(`2020`,`average \n2016-2019`,diff) %>%
gather(var,value) %>%
group_by(var) %>%
summarise(mean=mean(value))
moy_spread_aout_oct <-
figures %>%
na.omit() %>%
filter(month_day>="08-01",
month_day<="10-31") %>%
select(`2020`,`average \n2016-2019`,diff) %>%
gather(var,value) %>%
group_by(var) %>%
summarise(mean=mean(value))
plot_elec_temp <- ggplot(data=temp2,aes(month_day,value,colour=year,group=year))+
geom_line(size=1)+
scale_x_discrete(breaks=breaks_vec,
labels=labels_vec)+
scale_color_manual(values=ghibli_palette("MononokeMedium")[5:1])+
geom_ribbon(data=filter(figures,above==FALSE),aes(x=month_day,ymin=min,ymax=max,group=section_id),fill="#06141FFF",alpha=0.2,inherit.aes = F)+
geom_ribbon(data=filter(figures,above==TRUE),aes(x=month_day,ymin=min,ymax=max,group=section_id),fill="#CD4F38FF",alpha=0.2,inherit.aes = F)+
annotate("text",x="05-10",y=24,label="average of temperature deviations \nto the mean (Mar.-July) = +0.4")+
annotate("text",x="10-10",y=24,label="average of temperature deviations \nto the mean (Aug-Oct.) = +0.1")+
my_theme+
theme(legend.position = "none")+
labs(title="Average temperature",
subtitle = "in degrees, 7-day moving average",
x=NULL,y=NULL)
g <- grid.arrange(plot_elec_total_3, plot_elec_temp,nrow=2)
#ggsave("elec_temp.png",plot=g,width = 8.5,height=7)
```
We then look at electricity consumption by customer category.
```{r}
ggplot(filter(elec2,!var %in% c("Total consumption","Average temperature")),
aes(month_day,value,colour=year,group=year))+
geom_line(size=1)+
scale_y_continuous(labels = scales::number_format(accuracy = 1))+
scale_x_discrete(breaks=breaks_vec,
labels=labels_vec)+
scale_color_manual(values=ghibli_palette("MononokeMedium"))+
gghighlight(year != "average \n2016-2019",
use_direct_label = F,
calculate_per_facet = T,
unhighlighted_params = list(colour="transparent"))+
facet_wrap(~var,ncol=2,scales="free_y")+
my_theme+
theme(legend.position = c(0.75,0.25),
axis.text = element_text(size = 10))+
labs(title=title_client_vec,
subtitle = subtitle_vec,
x=NULL,y=NULL)
#ggsave("elec_compo_1.png",width = 8.5,height=7)
```
```{r}
ggplot(filter(elec2,!var %in% c("Total consumption","Average temperature")),
aes(month_day,value,colour=year,group=year))+
geom_line(size=1)+
scale_y_continuous(labels = scales::number_format(accuracy = 1))+
scale_x_discrete(breaks=breaks_vec,
labels=labels_vec)+
scale_color_manual(values=ghibli_palette("MononokeMedium")[5:1])+
gghighlight(year %in% c("average \n2016-2019","2020"),
use_direct_label = F,
calculate_per_facet = T,
unhighlighted_params = list(colour="transparent"))+
facet_wrap(~var,ncol=2,scales="free_y")+
my_theme+
theme(legend.position = c(0.78,0.14),
axis.text = element_text(size = 10))+
labs(title=title_client_vec,
subtitle = subtitle_vec,
x=NULL,y=NULL)
#ggsave("elec_compo_2.png",width = 8.5,height=7)
```
Residential electricity consumption appears to capture a significant portion of the variations due to temperature.
```{r}
figures <-
elec2 %>%
filter(!var %in% c("Total consumption","Average temperature"),
year %in% c("2020","average \n2016-2019")) %>%
spread(year,value) %>%
group_by(var) %>%
mutate(min=pmin(`2020`,`average \n2016-2019`),
max=pmax(`2020`,`average \n2016-2019`),
above=`2020`>=`average \n2016-2019`,
changed = is.na(lag(above)) | lag(above) != above,
section_id = cumsum(changed),
diff=`2020`-`average \n2016-2019`)
percent_first_lockdown <-
elec2 %>%
filter(!var %in% c("Total consumption","Average temperature"),
year %in% c("2020","average \n2016-2019")) %>%
group_by(var) %>%
filter(month_day>="03-17",
month_day<="05-11") %>%
group_by(year,var) %>%
summarise(sum=sum(value)) %>%
spread(year,sum) %>%
mutate(average_percent=(`2020`-`average \n2016-2019`)/`average \n2016-2019`,
average_per_day=(`2020`-`average \n2016-2019`)/56) #1st lockdown : 56 days
percent_second_lockdown <-
elec2 %>%
filter(!var %in% c("Total consumption","Average temperature"),
year %in% c("2020","average \n2016-2019")) %>%
group_by(var) %>%
filter(month_day>="11-01",
month_day<="11-27") %>%
group_by(year,var) %>%
summarise(sum=sum(value)) %>%
spread(year,sum) %>%
mutate(average_percent=(`2020`-`average \n2016-2019`)/`average \n2016-2019`,
average_per_day=(`2020`-`average \n2016-2019`)/27) #2nd lockdown : 27 days
ann_text <- data.frame(x = c("04-01","04-01","11-17","11-17"),
xend =c("04-01","04-01","11-17","11-17"),
y=c(12.5,5.4,5.6,12.9),
yend=c(10.1,4.2,4.55,12.15),
var = c("Large enterprises","Small and medium enterprises","Small and medium enterprises","Large enterprises"),
label=c("on average -20% \nduring 1st lockdown",
"on average -27% \nduring 1st lockdown",
"on average -18% \nduring 2nd lockdown\n(November)",
"on average -6% \nduring 2nd lockdown\n(November)"),
ylab=c(13.2,5.9,3.6,11),
xlab=c("05-10","05-30","10-10","10-10"))
ggplot(filter(elec2,!var %in% c("Total consumption","Average temperature")),
aes(month_day,value,colour=year,group=year))+
geom_line(size=1)+
scale_y_continuous(labels = scales::number_format(accuracy = 1))+
scale_x_discrete(breaks=breaks_vec,
labels=labels_vec)+
scale_color_manual(values=ghibli_palette("MononokeMedium")[5:1])+
gghighlight(year %in% c("average \n2016-2019","2020"),
use_direct_label = F,
calculate_per_facet = T,
unhighlighted_params = list(colour="transparent"))+
facet_wrap(~var,ncol=2,scales="free_y")+
geom_ribbon(data=filter(figures,above==FALSE),aes(x=month_day,ymin=min,ymax=max,group=section_id),fill="#06141FFF",alpha=0.2,inherit.aes = F)+
geom_ribbon(data=filter(figures,above==TRUE),aes(x=month_day,ymin=min,ymax=max,group=section_id),fill="#CD4F38FF",alpha=0.2,inherit.aes = F)+
geom_segment(data=ann_text,
mapping = aes(x = x, xend=xend, y = y, yend=yend),inherit.aes = F,
arrow=arrow(angle=40,length=unit(0.05,"inches")), size=1,colour="darkred")+
geom_text(data=ann_text,
mapping = aes(x=xlab, y=ylab,label=label),inherit.aes = F,
size=3.6,colour="darkred")+
my_theme+
theme(legend.position = c(0.78,0.14),
axis.text = element_text(size = 10))+
labs(title=title_client_vec,
subtitle = subtitle_vec,
x=NULL,y=NULL)
#ggsave("elec_compo_3.png",width = 8.5,height=7)
```
Large enterprises and SMEs experienced a net decrease (-20% and -27% respectively) during the 1st lockdown. The 2nd lockdown mainly impacts the electricity consumption of SMEs (-18% on average in November), even if large enterprises are also affected (-6% on average).
## Useful links :
- Retrieve all the data on DBnomics : https://db.nomics.world/ENEDIS/
- Reproduce and update the presentation with the code : https://git.nomics.world/macro/macro.nomics.world/tree/master/content/elec-conso-france
- High frequency data are available on DBnomics thanks to a partnership between Banque de France, Cepremap and OECD
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment