Created
July 24, 2022 06:33
-
-
Save cavedave/dc7529acd2033a547204ecf7ea70e678 to your computer and use it in GitHub Desktop.
UK electricity data from https://www.gridwatch.templar.co.uk/ Based on a previous heatmap https://gist.github.com/cavedave/2b99bd3b4e966c4f0211b6544a948026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(lubridate) | |
library(tidyverse) | |
gridwatch <- | |
read_csv( | |
file = "gridwatch.csv") | |
#get date int data format | |
gridwatch$timestamp<-ymd_hms(gridwatch$timestamp) | |
head(gridwatch) | |
data<-gridwatch %>% group_by(week=floor_date(gridwatch$timestamp, "week")) %>% | |
summarize(amount=sum(coal), rest=sum(demand)) | |
#make a column with % coal | |
data<-data %>% | |
mutate(perCoal = (amount/rest)*100) | |
data3<-data | |
#more cleaning up the dataframe | |
data3 <- data.frame(amount=data3$amount, | |
rest=data3$rest, | |
perCoal=data3$perCoal, | |
date = data3$week, | |
year = as.numeric(format(data3$week, format = "%Y")), | |
month = as.numeric(format(data3$week, format = "%m")), | |
week = as.numeric(format(data3$week, format = "%d"))) | |
data3$perCoal <- round(data3$perCoal) | |
head(data3) | |
#first and last weeks are partial messing up things remove them | |
dataw<-data3 | |
dataw = dataw[-1,] | |
dataw <- slice(dataw, 1:(n() - 1)) | |
#data source writes 23 gw as 23401 as current usage | |
#so i think get rid of last 3 numerals and tthats the gws | |
dataw$rest<-dataw$rest/1000 | |
dataw$rest<-round(dataw$rest) | |
A<-ggplot(data=dataw, aes(x=date, y=rest)) + | |
geom_line() | |
A <- A + scale_colour_grey() | |
plot.title = 'UK Electricity Usage' | |
plot.subtitle = 'Gridwatch Data' | |
A <- A + ggtitle(bquote(atop(.(plot.title), atop(italic(.(plot.subtitle)), "")))) | |
A <- A + scale_y_continuous() | |
A <- A + theme(panel.background = element_blank()) | |
#put this year at bottom | |
#gg<-gg + scale_y_reverse() | |
#change title and such | |
A <- A + theme(plot.title=element_text(hjust=0.5),legend.position="none") | |
#p <- p + theme(axis.text=element_text(size=12)) | |
A <- A+ theme(plot.title = element_text(size=17)) | |
#p <- p+ theme(plot.subtitle = element_text(size=10)) | |
A <- A+ xlab("") | |
A <- A+ ylab("Weekly GWatts") | |
A <- A + theme(axis.ticks=element_blank()) | |
A | |
ggsave("totalenergy.png", dpi=700) | |
#next graph | |
p<-ggplot(data=data3, aes(x=date, y=perCoal)) + | |
geom_bar(aes(fill = perCoal),stat="identity")+ | |
scale_fill_gradient(low = "lightgreen", high = "black", na.value = NA) | |
p | |
p <- p + scale_colour_grey(name="% UK power from Coal") | |
plot.title = 'UK Electricity from Coal' | |
plot.subtitle = 'Gridwatch Data' | |
p <- p + ggtitle(bquote(atop(.(plot.title), atop(italic(.(plot.subtitle)), "")))) | |
p <- p + scale_y_continuous(labels = scales::percent_format(scale = 1)) | |
p | |
p <- p + theme(panel.background = element_blank()) | |
#put this year at bottom | |
#gg<-gg + scale_y_reverse() | |
#change title and such | |
p <- p + theme(plot.title=element_text(hjust=0.5),legend.position="none") | |
#p <- p + theme(axis.text=element_text(size=12)) | |
p <- p+ theme(plot.title = element_text(size=17)) | |
#p <- p+ theme(plot.subtitle = element_text(size=10)) | |
p <- p+ xlab("") | |
p <- p+ ylab("") | |
p <- p + theme(axis.ticks=element_blank()) | |
p | |
ggsave("Barchart2.png", dpi=700) | |
Author
cavedave
commented
Jul 24, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment