To show only the results, large code chunks are hidden, but can be unfolded by clicking the “Code” boxes on the top right of each hidden code chunk.
Data Cleaning
The annual files were only merged to one. No additional data preparation is needed.
How Did The Pandemic Affect Swiss End-User Energy Consumption?
Code
# Aggregate to monthly valueselec <- electricity %>%mutate(date =as.character(substr(Zeitpunkt,1,10)),year =as.character(substr(Zeitpunkt,1,4)),month_in_year =month(Zeitpunkt)) %>%group_by(year, month_in_year) %>%summarise(kWh =sum(kWh),month_in_year =last(month_in_year),year =last(year)) %>%head(-1)elec %>%mutate(kWh = kWh/1000000) %>%ggplot(aes(x = month_in_year, y = kWh, color =as.factor(year))) +geom_line(size =0.7) +labs(title ="The effect of the COVID-19 pandemic on total energy consumption in Switzerland",subtitle ="End user electricity consumption in the Swiss controlblock by month (in millions of kWh)",x ="Calendar Month Number",y ="kWh (in millions)") +theme_minimal() +theme(plot.title =element_text(size =12, face="bold", colour="black"),plot.subtitle =element_text(face ="italic", colour ="gray50",size =10),legend.title =element_blank(),panel.grid.minor.x =element_blank(),panel.grid.minor.y =element_blank(),panel.grid.major.x =element_blank(),axis.title =element_text(size =10)) +scale_colour_manual(values =c(rep("gray75", 11), "red", "firebrick", "orange")) +scale_x_continuous(breaks =seq(1,12,1), limits =c(1,12)) +scale_y_continuous(labels = scales::comma_format())
Aggregating the data to monthly values and overlaying them for comparison reveals that the pandemic greatly impacted total energy consumption, especially during the first lockdown.
Are There Daily Patterns Within Each Week?
Code
elec <- electricity %>%mutate(hour =hour(Zeitpunkt),weekday =wday(Zeitpunkt, label =TRUE)) %>%group_by(hour, weekday) %>%summarise(mean_c =mean(kWh)) %>%mutate(weekday =ordered(weekday, levels =c("Mon", "Tue", "Wed", "Thu","Fri", "Sat", "Sun")))elec %>%ggplot(aes(x = hour+1, y = weekday)) +geom_tile(aes(fill = mean_c), width=0.95, height=0.95) +labs(title ="Swiss End-User Electricity Consumption: Hourly Usage Patterns Throughout Weekdays",subtitle ="Averages are formed based on historical data from the period 2009-2022",y ="Weekday",x ="Hour In The Day (Starting At Midnight)",fill ="Mean Consumption:") +scale_x_continuous(breaks =1:24, expand =c(0, 0)) +scale_fill_distiller(type ="seq", direction =1,labels = scales::comma_format(suffix =" kWh")) +theme_minimal() +theme(panel.grid =element_blank(),plot.title =element_text(size =12, face="bold", colour="black"),plot.subtitle =element_text(face ="italic", colour ="gray50",size =10),axis.title =element_text(size =10))
From the heat map above, it can be seen that peaks take place during weekday business hours, whereas the weekend looks milder. It can be concluded that the industry has a very high impact on total energy consumption.
Are Holiday Lows Visible?
Code
electricity %>%mutate(day =yday(Zeitpunkt),year =year(Zeitpunkt)) %>%group_by(day) %>%summarise(mean_kWh =mean(kWh),lower_kWh =quantile (kWh, 0.1),higher_kWh =quantile(kWh, 0.9)) %>%ggplot(aes(day, mean_kWh)) +geom_line(colour ="dodgerblue", size =0.75) +geom_ribbon(aes(ymin = lower_kWh, ymax = higher_kWh),colour ="dodgerblue", fill ="dodgerblue",alpha =0.5) +labs(title ="Daily Averages With Confidence Levels (10th And 90th Percentile)",subtitle ="Averages are formed based on historical data from the period 2009-2022",y ="kWh",x ="Day In The Year") +scale_y_continuous(labels = scales::comma_format()) +theme_minimal() +theme(plot.title =element_text(size =12, face="bold", colour="black"),plot.subtitle =element_text(face ="italic", colour ="gray50",size =10),axis.title =element_text(size =10))
Not only the mean, but also the confidence bands reveal a strong intra-year pattern, which in itself carries another weekly pattern shown in the heat map above. The lows during summer and Christmas holidays are considerable.