Tuesday, October 28, 2014

10 28 2014 Manchester Year 1 Temperature Update

ManTempConcat.R
library(plyr)
library(ggplot2)
library(scales)
manaugfeb<-read.table('ManAugtoFeb.csv', row.names=1)
#read in data, first change column names and remove data name in excel to make it work
head(manaugfeb)
##          V2    V3    V4
## 1 8/17/2013 10:00 21.28
## 2 8/17/2013 10:15 21.66
## 3 8/17/2013 10:30 21.86
## 4 8/17/2013 10:45 22.14
## 5 8/17/2013 11:00 22.24
## 6 8/17/2013 11:15 22.24
manaugfeb<-rename(manaugfeb, c("V2"="Date",'V3'='Time','V4'='Temp'))
#rename columns
manaugfeb$Date<-as.Date(manaugfeb$Date, "%m/%d/%Y")
#tell R that these are dates
tmptst<-ddply(manaugfeb,.(Date),summarise, mean_temp=mean(Temp,na.rm=T))
#creates mean temperature per date using summary statistics and ddply
plot(mean_temp~Date,data=tmptst)

plot of chunk unnamed-chunk-1

manfebmay<-read.table('ManchesterFebtoMay2014.csv', row.names=1)
manmayjun<-read.table('ManchesterMaytoJun14.csv', row.names=1)
manjunjul<-read.table('ManchesterJuntoJul14.csv', row.names=1)
#entered in all other CSVs
manfebmay<-rename(manfebmay, c("V2"="Date",'V3'='Time','V4'='Temp'))
manmayjun<-rename(manmayjun, c("V2"="Date",'V3'='Time','V4'='Temp'))
manjunjul<-rename(manjunjul, c("V2"="Date",'V3'='Time','V4'='Temp'))
#rename columns
manfebmay$Date<-as.Date(manfebmay$Date, "%m/%d/%Y")
manmayjun$Date<-as.Date(manmayjun$Date, "%m/%d/%Y")
manjunjul$Date<-as.Date(manjunjul$Date, "%m/%d/%Y")
#Date column as dates
many1<-rbind(manaugfeb,manfebmay,manmayjun,manjunjul)
#concats all temp data

#creates csv for manual editting in excel. Manual editting used to remove artifacts
many1edit<-read.csv("manY1.csv")
#reads in edited CSV to correct for outliers.
manjuloct<-read.table('ManchesterJultoOct2014.csv')
manaugoct<-read.table('ManchesterAugtoOct2014.csv')
#reads in new temp data from jul and aug to october 2014
manjuloct<-rename(manjuloct, c("V2"="Date",'V3'='Time','V4'='Temp'))
manaugoct<-rename(manaugoct, c("V2"="Date",'V3'='Time','V4'='Temp'))
#renames things
manjuloct$Date<-as.Date(manjuloct$Date, "%m/%d/%Y")
manaugoct$Date<-as.Date(manaugoct$Date, "%m/%d/%Y")
manoct<-merge(manjuloct, manaugoct,by=c("Date","Time","Temp"),all=T,sort=F)
manoct$Date<-as.Date(manoct$Date)
many1edit$Date<-as.Date(many1edit$Date)
many1edit2<-merge(many1edit,manoct, by=c("Date","Time","Temp"),all=T,sort=F)
#creates new data frame for all y1 temps
many1edit2$Date<-as.Date(many1edit2$Date)
#Dates as DATES in r

many1v3<-read.csv('many1v3_3.csv')
many1v3$Date<-as.Date(many1v3$Date,"%m/%d/%Y")
manmeantemp<-ddply(many1v3,.(Date),summarise,mean_temp=mean(Temp,na.rm=T))
#creates mean temp file
manmintemp<-ddply(many1v3,.(Date),summarise,min_temp=min(Temp,na.rm=T))
#creates min temp file
manmaxtemp<-ddply(many1v3,.(Date),summarise,max_temp=max(Temp,na.rm=T))
#creates max temp file
manmedtemp<-ddply(many1v3,.(Date),summarise,med_temp=median(Temp,na.rm=T))
#creates med temp file
ggplot(data=manmedtemp, aes(Date, med_temp, group=1))+geom_line(color="Sky Blue",size=1.5)+geom_abline(intercept=12.5, slope=0,color="red", size=2)+scale_x_date(breaks="1 month", minor_breaks="1 week",labels=date_format("%B %Y"))+theme(axis.text.x=element_text(angle=45, size=10, vjust=0.5))

plot of chunk unnamed-chunk-1

#plots median temps
ggplot(data=manmintemp, aes(Date, min_temp, group=1))+geom_line(color="Sky Blue",size=1.5)+geom_abline(intercept=12.5, slope=0,color="red", size=2)+scale_x_date(breaks="1 month", minor_breaks="1 week",labels=date_format("%B %Y"))+theme(axis.text.x=element_text(angle=45, size=10, vjust=0.5))

plot of chunk unnamed-chunk-1

#plots min temps
ggplot()+geom_line(data=manmeantemp, aes(Date,mean_temp, group=1), color="Sky Blue",size=1)+geom_line(data=manmintemp, aes(Date,min_temp,group=1),color="blue",size=1)+geom_line(data=manmaxtemp,aes(Date,max_temp,group=1),color="red",size=1)+geom_abline(intercept=12.5, slope=0,color="red", size=0.5)+labs(x="Date",y="Min|Max|Mean Temperatures(C)")+scale_x_date(breaks="1 month", minor_breaks="1 week",labels=date_format("%B %Y"))+theme(axis.text.x=element_text(angle=45, size=10, vjust=0.5))

plot of chunk unnamed-chunk-1

#plots all temps

No comments:

Post a Comment