Skip to content

Instantly share code, notes, and snippets.

@cavedave
Last active February 25, 2019 23:09
Show Gist options
  • Save cavedave/d8fc4b85f6154d68f302cd39585d443c to your computer and use it in GitHub Desktop.
Save cavedave/d8fc4b85f6154d68f302cd39585d443c to your computer and use it in GitHub Desktop.
Code to look at CET and find the hottest days on a particular date
library(tidyverse)
library(lubridate)
#get data from https://www.metoffice.gov.uk/hadobs/hadcet/data/download.html
#CET2 <- url("https://www.metoffice.gov.uk/hadobs/hadcet/cetmaxdly1878on_urbadj4.dat") or cetdl1772on2018.dat for mean daily temps
cet2 <- read.table("/Users/davidcurran/Documents/cetmaxdly1878.dat", sep = "", header = FALSE,
fill = TRUE)#,na.string = c(-99.99, -99.9, -999)
colnames(cet2) <- c("year","day","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
data_long <- gather(cet2, month, temp, Jan:Dec)#, factor_key=TRUE)
data_long$temp<-(data_long$temp/10)
head(data_long)
df_raw<-data_long
Feb25<-filter(df_raw, month == 'Feb', day == 25)
Feb25[Feb25$temp>= 13.00,]
library(ggplot2)
# Basic scatter plot
p<-ggplot(Feb25, aes(x=year, y=temp)) + geom_point()
p=p+ggtitle("Maximum Temperature on Feb 25th\n Central England since 1878") +xlab("Year") + ylab("Max Temp C")
p=p + theme_bw()
ggsave("Feb25th.png")
@cavedave
Copy link
Author

feb25th

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment