#FUnctions Kaufmann #plots- require gplots library(gplots) opar <- par(mar=c(4,4,2,2),las=1) source("http://www.climateaudit.org/scripts/utilities.txt") f=function(x) filter.combine.pad(x,truncated.gauss.weights(21))[,2] g=function(X) ts(X[,2],start=X[1,1]) plotf3=function(x,col0="pink2",col1=2,ylab0="SD Units" ,xlim1=c(400,2000),ylim1=range(x,na.rm=T), start.med=950,end.med=1100,start.mod=1856,end.mod=1980,start0=1980,smoothmethod=TRUE) { year=c(time(x));N=length(x) par(mar=c(4,4,2,2),bg="grey80") plot(year,x,ylim=ylim1,type="n",xlim=xlim1,axes=FALSE,xlab="",ylab=ylab0) usr <- par("usr") rect(usr[1],usr[3],start.med ,usr[4],border=NA,col="lavender") # - the part used to fit the model rect(start.med ,usr[3],usr[2],end.med,border=NA,col="lemonchiffon") # - the part used to make the forecast rect(end.med ,usr[3],usr[2],end.med,border=NA,col="lavender") # - the part used to make the forecast rect(start.mod ,usr[3],usr[2],end.med,border=NA,col="lemonchiffon") # - the part used to make the forecast rect(end.mod ,usr[3],usr[2],end.med,border=NA,col="lavender") # - the part used to make the forecast abline(h= (-3:3)*2 , col ="gray" , lty =3) abline(v= seq(800,2000,200) , col ="gray" , lty =3) temp1=!is.na(x);M=sum(temp1);year=c(time(x))[temp1] x=x[temp1] lines(year,x,col=col0,type="h") if(smoothmethod) lines(year,f(x),col=col1,lwd=2) title(paste(title0)) axis(side=1,col=1,font=2,col.axis=1) axis(side=2,col=1,font=2,col.axis=1,las=1) #smartlegend(x="left",y="bottom",fill=c(2,4),legend=c("Briffa","Grudd"),inset=0,bg="gray80") box();abline(h=0,lty=2) #mtext(side=2,ylab0,line=2,font=2) }