How to use ggplot2 to plot French electricity data

Posted on Updated on

I’m going to start doing two or more shortish posts per week looking at energy and electricity data. This will involve a couple of things. First, I’ll be posting time series of wind farm output etc. etc, and then talking and venting around them. But, more importantly, I’ll be posting the code and data sources used to generate the figures.

Some of the posts will be short, some will be long.

Here is the first topic.

What does the average day look like on the French electricity grid?

Fortunately, France publishes excellent data, which is available here. So, this question is easy to answer. Half hourly production from each source – nuclear, coal, wind, solar, etc. – are all available historically.

So, what does the average half hourly output look like? Below is the data plotted for 2013, along with the average CO2 intensity of production.

DailyUnsurprisingly, consumption varies throughout the day. The French are mammals who sleep at night.

Wind power appears to have a significant average daily cycle. I plan to look into this later.

Pumped storage is negative, because this represents electricity that is being stored. As far as I understand it, when storage facilities are producing electricity that goes under “Hydro”. So, the hydro statistics are slightly confusing. France, of course, has high levels of energy storage precisely because it has high levels of nuclear energy. There are misinformed individuals who imagine that Elon Musk has just killed nuclear energy with a battery; yet, the historical connection of nuclear and pumped storage slightly refutes this hypothesis.

The average CO2 intensity is very low by the standards of industrial countries, almost ten times lower than Britain or Germany. But, it shows a slight daily cycle. This is mostly because France tends to meet peak daily electricity demand by ramping up its fossil fuel power plants.

I probably have more to say on solar in France, but wait for that next week….

R code


require(ggplot2);require(lubridate);require(reshape2);require(gridExtra)

### Read in file. Uncheck the names because they have characterse that screw up R
### Download "<a href="http://eco2mix.rte-france.com/download/eco2mix/eCO2mix_RTE_Annuel-Definitif_2013.zip">Definitive data for the year 2013</a>" from http://www.rte-france.com/en/eco2mix/eco2mix-telechargement-en
raw <- read.csv("~France/eCO2mix_RTE_Annuel-Definitif_2013.csv", check.names = F)
### restrict the data to what I want to plot here
raw <- raw[,c(1:15,18)]
## Create English headings. Prévision is prediction. I'm not sure what this means in practise.
names(raw) <- c("Country",  "Nature", "Date",	"Hour",	"Consumption",	"Prediction.J.1", "Prediction.J",		"Oil",	"Coal",
                "Gas",	"Nuclear",	"Wind",	"Solar",	"Hydro", "Pumped.Storage", "CO2")
### The data is only available half hourly by source. Let's remove the non-existant 
raw <- subset(raw, !is.na(Solar))

### Convert the date loaded in to an actual R date
raw$Date <- dmy(raw$Date)
### Now, let's create a data frame that is half usable.....

df <- data.frame(Day = day(raw$Date), Month = month(raw$Date), Time = as.integer(substr(raw$Hour,1,2)) +  as.integer(substr(raw$Hour,4,5))/60,
                 Consumption = raw$Consumption,Nuclear = raw$Nuclear, Hydro = raw$Hydro, Coal = raw$Coal, Oil= raw$Oil, Gas = raw$Gas, Wind = raw$Wind, Solar = raw$Solar, CO2 = raw$CO2,
                 Storage = raw$Pumped.Storage)
### Aggregate the data, so that it is averaged by time period, and then melt it into one data frame that can be plotted using facets
df.hour <- aggregate(df, by = list(df$Time), FUN = mean)[,4:14]
df.melt <- melt(df.hour, id.vars = "Time")

df.elec <- subset(df.melt, variable %in% "CO2" != T)

## Plot the electricity data ###
gg1 <- ggplot(df.elec, aes(Time, value))+
  geom_line()+
  facet_wrap(~variable, scales = "free_y", ncol = 3)+
  xlab("Hour of day")+
  ylab("Average power output (MW)")+
  theme_grey(base_size = 16)+
  scale_x_continuous(breaks = seq(0,24,3))

df.co2 <- subset(df.melt, variable %in% "CO2")

gg2 <- ggplot(df.co2, aes(Time, value))+
  geom_line()+
  xlab("Hour of day")+
  ylab("Average CO2 intensity (g CO2/kWh)")+
  theme_grey(base_size = 16)+
  scale_x_continuous(breaks = seq(0,24,2))

### Combine the plots
grid.arrange(gg1, gg2, nrow = 2)





Advertisements