Skip to content

Instantly share code, notes, and snippets.

@vanatteveldt
Created May 9, 2019 19:21
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/b4513d4399042b6b9cad79600a98826f to your computer and use it in GitHub Desktop.
Save vanatteveldt/b4513d4399042b6b9cad79600a98826f to your computer and use it in GitHub Desktop.
library(tidyverse)
data = read_csv("https://www.ofgem.gov.uk/node/98510/revisions/321984/csv") %>% separate(Date, into=c("q", "y")) %>% gather(-q, -y, key="type", value="perc")
data %>% group_by(y, type) %>% summarize(p = mean(perc)) %>% filter(type %in% c("Gas", "Coal", "Nuclear", "Bioenergy", "Wind (onshore and offshore) and Solar")) %>%
ggplot() + geom_line(aes(x=as.numeric(y), y=p, colour=type)) + ggthemes::theme_economist() + xlab("Year") + ylab("% of electricity generated")
data %>% group_by(y, type) %>% summarize(p = mean(perc)) %>%
mutate(type=case_when(type %in% c("Gas", "Coal") ~ "Gas & Coal", type %in% c("Bioenergy", "Wind (onshore and offshore) and Solar") ~ "Wind & Solar & Bio", T ~ "other")) %>%
group_by(y, type) %>% summarize(p = sum(p)) %>%
ggplot() + geom_line(aes(x=as.numeric(y), y=p, colour=type)) + ggthemes::theme_economist() + xlab("Year") + ylab("% of electricity generated")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment