Dataset from week 20 of Andy Cotgreave and Andy Kriebel’s #Makeovermonday challenge
library(stringr)
library(dplyr)
library(ggplot2)
#Download file from onedrive if needed
if(!file.exists("temperatures.txt")){
download.file("https://onedrive.live.com/download.aspx?cid=43EBDBC5D5265516&authKey=%21AH1yAX86LpyUja4&resid=43EBDBC5D5265516%2110356&ithint=%2Etxt","temperatures.txt")
}
#Load text file
temperatures.raw <- read.csv("temperatures.txt", sep = "\t", stringsAsFactors = FALSE)
#Create named month and numeric year columns
temperatures.dates <- as.data.frame(str_split_fixed(temperatures.raw$Year,"/",2))
temperatures.dates <- temperatures.dates %>%
rename(year_num = V1,
month_num = V2) %>%
mutate(month_name = month.name[month_num],
year_num = as.numeric(year_num))
temperatures <- cbind(temperatures.raw, temperatures.dates)
#Sort months
temperatures$month_name <- factor(temperatures$month_name, levels = month.name)
#Plot Data
ggplot(data=temperatures, aes(x=year_num, y=Median, colour=Median)) +
geom_line() +
scale_colour_gradient(low="yellow", high="Red") +
facet_wrap(~ month_name) +
theme(axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank())