Skip to content

Instantly share code, notes, and snippets.

@cavedave
Last active August 1, 2019 12:38
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 cavedave/4ad820a633c038223b9b8c36d4681005 to your computer and use it in GitHub Desktop.
Save cavedave/4ad820a633c038223b9b8c36d4681005 to your computer and use it in GitHub Desktop.
Picture of Temperatures in Jul in Central England
library(tidyverse)
library(lubridate)
library(RCurl)
#data from https://www.metoffice.gov.uk/hadobs/hadcet/cetmaxdly1878on_urbadj4.dat
cet2 <- read.table("cetmaxdly1878on_urbadj4.dat", sep = "", header = FALSE, #cetmaxdly1878on_urbadj4
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
Jul<-filter(df_raw, month == 'Jul')
tail(Jul,40)
#make bins of the temperatures (and decades)
df_raw$Periods <- cut(df_raw$year, breaks=c(1877,1900,1920,1940,1960,1980,2000,2018 ,Inf), labels=c("1878-1900","1901-1920","1921-1940","1941-1960","1961-1980","1981-2000","2001-2018","2019"))
df_raw$temps <- cut(df_raw$temp, breaks=c(12,15,18,21,24,27,30, 33, Inf), labels=c("12-15","15-18","18-21","21-24","24-27","27-30","30-33","33+"))
#Colors
cbp1 <- c("#999999", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00", "#000000")#"#CC79A7")
hot <- c("#6BBCD1","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#b10026","#800026")
#Just get July
Jul<-filter(df_raw, month == 'Jul')
#make a picture
library(ggplot2)
# Basic scatter plot
p<-ggplot(Jul, aes(x=year, y=temp, color=temps )) + geom_point()
p=p+ggtitle("Maximum temperature each July day Central England") +xlab("Year") + ylab("Max Temp °C")
p=p+geom_smooth(method=lm, colour="black")
# To use for line and point colors, add
#p=p + scale_colour_manual(values=cbp1) RdBu
p=p + scale_colour_manual(values=hot)
#p=p +scale_shape_manual(values=c(0, 10, 20,30))
#p=p + scale_color_brewer(palette = "RdBu")
#p=p + annotate("text", x = 2006.5, y = 32.1, label = "2006",colour = "black")
p=p + annotate("text", x = 1985, y = 12.5, label = "data: metoffice.gov.uk by @iamreddave",colour = "black", size=2.5)
p=p + theme_bw()
p=p+theme(plot.title = element_text(hjust = 0.5))
p
ggsave("JulyEng.png")
#Other stuff
Jul[which.max(Jul$temp),]
#2019 25 Jul 34.1 2019
#See what July 19 looks like stats wise.
Jul19<-filter(Jul, year == 2019)
summary(Jul19)
Min. :17.50
Mean :22.27
@cavedave
Copy link
Author

cavedave commented Aug 1, 2019

JulyEng

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