# R code developed by: # International Research Institute for Climate and Society # Columbia University in the City of New York, USA # Last update: Jully 3, 2013 # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- # FUNCTION : Plot_Comparison # -------------------------------------------------------------------------------- # Dependancies : (see each function for further details) # NONE # -------------------------------------------------------------------------------- # Results : # -- A plot of all the vectors contained in the list A # -------------------------------------------------------------------------------- # Parameters : # -- A the list of vectors to be plotted # -- Alegend the corresponding list of the legends for each vector # -- xlegend the label for x - axis # -- ylegend the label for y - axis # -- title the global title of the plot # -------------------------------------------------------------------------------- Plot_Comparison<-function(A,Alegend,xlegend,ylegend,title) { plot.new() # Aprime is a big vectors with all the elements of the vectors of A Aprime<-NULL; for (i in 1:length(A)){ Aprime<-cbind(Aprime,A[[i]]) } # Set the bounds of the plot (global min and max of all the vectors) ymax<-max(Aprime) ymin<-min(Aprime) # Set the labels and create the window plot.window(c(1,12), c(ymin,ymax)) axis(1, at=seq(1,12,by=1)) axis(2, at=seq(min(c(floor(10*ymin-1)/10,0)),floor(10*ymax+1)/10,by=(floor(10*ymax+1)/10-floor(10*ymin-1)/10)/2/10)) box() # Plot each vector for (i in 1:length(A)) { lines(A[[i]], type="o", col=i, pch=1) } title(main=title, col.main="black", font.main=1) title(xlab=xlegend) title(ylab=ylegend) if (!is.null(Alegend)){ legend("topright", Alegend, cex=0.8, col=1:length(A), pch=1, horiz=FALSE, text.width=4, y.intersp=3); } } # -------------------------------------------------------------------------------- # FUNCTION : Plot_These # -------------------------------------------------------------------------------- # Dependancies : (see each function for further details) # -- Function "Plot_Comparison" # -------------------------------------------------------------------------------- # Results : # -- A plot of all the selected scores for the selected models # -------------------------------------------------------------------------------- # Parameters : # -- Models the list of the scores to be plotted # -- L the lead time to take for the scores # -- Scores the list of the names of the scores to be plotted # -- Names the vector of the names of the models for which the scores are extracted # -- anomalies=TRUE or FASLE : wether to plot the scores on the anomalies of the nominal values # -------------------------------------------------------------------------------- Plot_These<-function(Models,L,Scores,Names,method,anomalies){ # Make the title of the plot according to parameters if (anomalies){ leg<-paste(L," months predictions for the ",method," corrected models, anomalies") } else { leg<-paste(L," months predictions for the ",method," corrected models") } # Plot all the scores for (i in 1:length(Scores)) { plott<-NULL for (j in 1:length(Models)) { plott[[j]]<-Models[[j]][[Scores[[i]]]] } if (i==1){ Plot_Comparison(plott,Names,"Ending time of the simulation (Sm+L), from January to December",Scores[[i]],leg) } else { Plot_Comparison(plott,NULL,"Ending time of the simulation (Sm+L), from January to December",Scores[[i]],"") } } }