OxTemp <- read.table("http://pastebin.com/raw.php?i=37zUkaA4",header=TRUE,stringsAsFactors=FALSE)
library(ggplot2)
OxTemp$Month <- factor(OxTemp$Month,
levels=c("Jan", "Feb", "Mar","Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), ordered=TRUE)
OxTemp$Season <- factor(OxTemp$Season,
levels=c("Spring", "Summer", "Autumn", "Winter"), ordered=TRUE)
library(plyr)
slopedat <- ddply(OxTemp,.(Month),function(df) data.frame(slope=format(signif(coef(lm(MaxT~Year,data=df))[2],2),scientific=-2),
y=max(predict(lm(MaxT~Year,data=df)))))
p <- ggplot(OxTemp, aes(x=Year, y=MaxT)) +
geom_smooth(aes(group=Month, colour=Season, linetype=Month),method = 'lm',size = 1, se = F) +
scale_colour_manual(values=c("Winter"= 4, "Spring" = 1, "Summer" = 2,"Autumn" = 3)) +
geom_text(data=slopedat,aes(x=2005,y=y,label=paste0("slope = ",slope))) +
scale_x_continuous(limits=c(1950, 2010)) +
guides(linetype=guide_legend(override.aes=list(colour=c("Jan"= 4, "Feb" = 4, "Mar" = 1,
"Apr" = 1, "May" = 1, "Jun" = 2,
"Jul" = 2, "Aug" = 2, "Sep" = 3,
"Oct" = 3, "Nov" = 3, "Dec" = 4)),keywidth=5))
print(p)