Skip to content

Instantly share code, notes, and snippets.

@cavedave
Created August 14, 2020 17:24
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/9e94d345ebb19eec3b47228dd60c62dd to your computer and use it in GitHub Desktop.
Save cavedave/9e94d345ebb19eec3b47228dd60c62dd to your computer and use it in GitHub Desktop.
Central England's Highest, Lowest and Average temp each year since 1878
library(tidyverse)
library(lubridate)
library(RCurl)
library(reshape2)
#URL <- "https://www.metoffice.gov.uk/hadobs/hadcet/cetmaxdly1878on_urbadj4.dat"
cet2 <- read.table("cetmaxdly1878on_urbadj4.dat.txt", 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")
cet2<-filter(cet2, t > -99 )%>%
na.omit()
data_long <- gather(cet2, month, t, Jan:Dec)#, factor_key=TRUE)
data_long$t<-(data_long$t/10)
#head(data_long)
df_raw<-data_long
#Make divisions by time and temperature
#Make months go in time order not alphabetical
df_raw$month = factor(df_raw$month, levels = month.abb)
#get rid of na's
df_raw<-filter(df_raw, t > -99 )%>%
na.omit()
highest<-df_raw%>% group_by(year) %>% summarise(Max_temp = max(t))
lowest<-df_raw%>% group_by(year) %>% summarise(Min_temp = min(t))
mean<-df_raw%>% group_by(year) %>% summarise(Mean_temp = mean(t))
all_rows2 <- full_join(highest, lowest,
by = c("year" = "year"))
all_rows2 <- full_join(all_rows2, mean,
by = c("year" = "year"))
mdata <- melt(all_rows2, id=c("year"))
head(mdata)
mdata<-rename(mdata, Temp=variable)
p<-ggplot(data=mdata, aes(x=year, y=value, group=Temp)) +
geom_line(aes(color=Temp))+
geom_point(aes(color=Temp))+geom_smooth(method=loess, colour="black")
p<-p+ggtitle("Temperature Each Year in Central England") +xlab("Year") + ylab("Max and Min Temp °C")
p<-p+scale_color_manual(values=c("#FA1E44", "#00b4EB","#E69F00"))
p=p + theme_bw()
p=p+theme(plot.title = element_text(hjust = 0.5))
ggsave("MaxMin.png", width = 30, height = 20, units = "cm")
p
@cavedave
Copy link
Author

MaxMin

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