{ # read in the data file as a matrix of 13 columns # first column is the year and the next 12 are the monthly # rainfall values #commands to read data, calculate basic monthly statistics, plot #them for each month and also boxplots and histograms #commands to perform robust stats - median, IQR, etc. #commands to do a bivariate histogram #read in data.. rain=matrix(scan("aismr.txt"),ncol=13,byrow=T) #pick the monthly rainfall values excluding the year. rain1=rain[,2:13] years=rain[,1] #1871 - 1999 N=length(years) #of years N1=N-1 #read the NINO3 index.. test=matrix(scan("nino3-index.txt"),ncol=3,byrow=T) nino3=matrix(test[,3],ncol=12,byrow=T) #get the nino3 of the summer (June - Sep) season nino3ses=apply(nino3[,6:9],1,mean) #get the seasonal rainfall for the common years - i.e. 1900 - 1999 N=1999-1900+1 N2=1900-1871+1 N3=N2+N-1 sesrain=apply(rain1[,6:9],1,mean) sesrain=sesrain[N2:N3] ############################# #bivariate histogram of NINO3 and AllIndia rainfall library(gplots) library(akima) #perhaps not required wth gplots.. h2d <- hist2d(sesrain,nino3ses,show=FALSE, same.scale=TRUE, nbins=c(20,30)) persp( h2d$x, h2d$y, h2d$counts, ticktype="detailed", theta=30, phi=30, expand=0.5, shade=0.5, col="cyan", ltheta=-30) }