##HADLEY CENTER MONTHLY DATA #this is a short script to plot CET monthly data (Centered) and to calculate years of indovidual monthly maxima url<-"http://www.metoffice.com/research/hadleycentre/CR_data/Daily/HadCET_act.txt" cet<-read.table(url,skip=7) temp<-(cet< -90) cet[temp]<-NA range(cet[,1]) # 1659 2006 id<-scan(url,skip=6,n=13,what="") dimnames(cet)[[2]]<-c(id[c(13,1:12)],"ANNUAL") cet<-ts(cet,start=1659) cet.centered<-scale(cet[,2:13],scale=FALSE) ylim0=c(-4.5,4.5) #PLOT MONTHLY CENTERED DATA nf<-layout(array(1:12,dim=c(6,2)),heights=c(1.1,1,1,1,1,1.3),widths=c(1.1,1)) par(mar=c(0,3,1,0));i<-1 plot(1659:2006,cet.centered[,1],type="l",axes=FALSE,ylim=ylim0) axis(side=1,labels=FALSE);axis(side=2,las=1);box();abline(h=0,lty=2);text(1659,4,paste(id[i]),pos=4) for (i in 2:5){ par(mar=c(0,3,0,0)) plot(1659:2006,cet.centered[,i],type="l",axes=FALSE,ylim=ylim0) axis(side=1,labels=FALSE);axis(side=2,las=1);box();abline(h=0,lty=2);text(1659,4,paste(id[i]),pos=4) } par(mar=c(3,3,0,0));i<-6 plot(1659:2006,cet.centered[,6],type="l",axes=FALSE,ylim=ylim0) axis(side=1);axis(side=2,las=1);box();abline(h=0,lty=2);text(1659,4,paste(id[i]),pos=4) par(mar=c(0,0,1,1));i<-7 plot(1659:2006,cet.centered[,7],type="l",axes=FALSE,ylim=ylim0) axis(side=1,labels=FALSE);axis(side=2,labels=FALSE);box();abline(h=0,lty=2);text(1659,4,paste(id[i]),pos=4) for (i in 8:11){ par(mar=c(0,0,0,1)) plot(1659:2006,cet.centered[,i],type="l",axes=FALSE,ylim=ylim0) axis(side=1,labels=FALSE);axis(side=2,labels=FALSE);box();abline(h=0,lty=2);text(1659,4,paste(id[i]),pos=4) } par(mar=c(3,0,0,1));i<-12 plot(1659:2006,cet.centered[,12],type="l",axes=FALSE,ylim=ylim0) axis(side=1);axis(side=2,labels=FALSE);box();abline(h=0,lty=2);text(1659,4,paste(id[i]),pos=4) ##MAXIMA f<-function(x) { f<- (1659:2006)[(x==max(x,na.rm=T))&!is.na(x)];f} test<- c(apply(cet[,2:13],2,f)) test #$JAN [1] 1916 #$FEB [1] 1779 #$MAR [1] 1957 $APR [1] 1865 $MAY [1] 1833 $JUN [1] 1846 $JUL [1] 2006 $AUG[1] 1995 $SEP[1] 1729 $OCT [1] 2001 $NOV [1] 1994 $DEC [1] 1934 1974 sd0<-apply(cet.centered,2,sd,na.rm=T) # JAN FEB MAR APR MAY JUN #1.476546 1.567833 1.475023 1.192737 1.146211 1.095677 # JUL AUG SEP OCT NOV DEC #1.155224 1.091122 1.112100 1.293744 1.358435 1.529635 cet.centered[2006-1658,]/sd0 cet.scaled<-scale(cet.centered,center=FALSE,scale=sd0) g<- function(x){g<-max(x,na.rm=t);g} apply(cet.scaled,2,g) # JAN FEB MAR APR MAY JUN JUL AUG SEP OCT #2.549591 2.424894 2.641494 2.262497 3.397501 3.538463 3.236422 3.273811 2.954663 2.808016 # NOV DEC #2.998025 2.515365