Skip to content

Instantly share code, notes, and snippets.

@vanatteveldt
Created January 8, 2020 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanatteveldt/41266921a9aba3a1397dff4e4c94f41b to your computer and use it in GitHub Desktop.
Save vanatteveldt/41266921a9aba3a1397dff4e4c94f41b to your computer and use it in GitHub Desktop.
# get data from https://opendata.cbs.nl/statline/#/CBS/nl/dataset/80030NED/table?fromstatweb
library(cbsodataR)
library(tidyverse)
d = cbs_get_data("80030NED") %>% cbs_add_date_column() %>% cbs_add_label_columns() %>%
filter(CentraleDecentraleProductie_label=="Totaal centrale/decentrale productie") %>%
select(date=Perioden_Date, source=Energiedragers_label, elec=ElektriciteitMWh_2)
# filter and translate energy sources
sources = c(coal="Steenkool", oil="Stookolie", gas="Aardgas", biomass="Biomassa", nuclear="Kernenergie", solar="Zonnestroom", wind="Windenergie", water="Waterkracht")
d = d %>% filter(source %in% sources) %>% mutate(source=names(sources)[match(source, sources)])
d = d %>% group_by(date) %>% mutate(perc = elec / sum(elec))
# plot
library(RColorBrewer)
colors = c(brewer.pal(5, "Reds")[3:5], brewer.pal(3, "Purples")[2:3], brewer.pal(5, "Greens")[3:5])
ggplot(d, aes(x=date, y=perc*100, fill=fct_relevel(source, names(sources)))) + geom_area() +
scale_fill_manual(name="Source", values=colors) + ggthemes::theme_fivethirtyeight()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment