# David Hopp, Durham NC USA. cassiodorus at hotmail dot com # June 2011 all rights reserved but free use transferred to you on basis of Creative Commons license. # This is proof-of-concept not a lesson in html or javascript. # Gratitude is due the CLIWOC Project team for their excellent work. # rev 27Jun2011 setwd("c:/programdata/rwork") load(".Rdata") # -------------------------------------------- # computations already done in the spreadsheet # -------------------------------------------- fileNstart <- "CLIWOC21CORE_Miller_" #default fileNend <- ".png" #default CC2Country <- c("UK", "NL", "ES", "FR") #do not change #red, orange, brick red, blue #myColors <- c("#CE1124", "#FFA500", "#B0081c", "#0E00D4") myColors <- c("#CE1124", "#B0081c", "#B0081c", "#CE1124") #mySymbols <- c(1, 3, 4, 8) mySymbols <- c(20, 20, 20, 20) #use these to select which graphics to print prtCum <- TRUE prt3yr <- TRUE prt1yr <- TRUE #pass thru the csv files and do all the work to create the pngs createThePngs <- function (){ opar <- par(no.readonly=TRUE) #for (C in 1:4) { # TEMPORARY DETOUR WHEN NEEDED - should be 1:4 for (C in 1:4) { #initialize #rm(dataFile) #just being careful country <- CC2Country[C] dataFile <- read.table(paste("Miller-cliwoc-",country,"1750-1810-noNA.csv",sep=""),header=TRUE,sep=",",stringsAsFactor=FALSE) #determine the years that appear in the table theYears <- sort(unique(dataFile[,1])) numYears <- length(theYears) startYear <- theYears[1] maxYear <- theYears[numYears] #produce the select lists selectFileName <- paste("selectList", country, ".txt", sep="") cat("", file=selectFileName, append=TRUE, sep="") arrayFileName <- paste("arrayList", country, ".txt", sep="") cat(numYears, file=arrayFileName) cat(theYears, file=arrayFileName, sep=",", append=TRUE) #Miller mapping computations done in spreadsheet #dataFile$Lon * 4 -> xcoord #f * ln(tan((45 + 0.4 * dataFile$Lat) * dTr)) -> ycoord #scale to width and height of map for (Y in 1:numYears) { yYear <- theYears[Y] #cumulative if (prtCum) { fileName <- paste(fileNstart,startYear,"thru",yYear,"_",country,fileNend,sep="") png(fileName, width=480, height=480, units="px") #defaults par(mar=c(0,0,0,0),xaxt="n",yaxt="n",oma=c(0,0,0,0), cex=0.70) #no margins, no axes plot(ycoord ~ xcoord,data=dataFile[dataFile$Year >= startYear & dataFile$Year <= yYear & dataFile$CC2 == C,], ylim=c(-201,279),xlim=c(-265,215),col=myColors[C],pch=mySymbols[C],bg="transparent") dev.off() } #one year if (prt1yr) { fileName <- paste(fileNstart,yYear,"_",country,fileNend,sep="") png(fileName, width=480, height=480, units="px") par(mar=c(0,0,0,0),xaxt="n",yaxt="n",oma=c(0,0,0,0), cex=0.70) #no margins, no axes plot(ycoord ~ xcoord,data=dataFile[dataFile$Year == yYear & dataFile$CC2 == C,], ylim=c(-201,279),xlim=c(-265,215),col=myColors[C],pch=mySymbols[C],bg="transparent") dev.off() } #sliding three year if (prt3yr) { #sliding 3-year window if (yYear <= (maxYear-2)) { fileName <- paste(fileNstart,"sliding3year_",yYear,"thru",(yYear+2),"_",country,fileNend,sep="") png(fileName, width=480, height=480, units="px") par(mar=c(0,0,0,0),xaxt="n",yaxt="n",oma=c(0,0,0,0), cex=0.70) #no margins, no axes plot(ycoord ~ xcoord,data=dataFile[dataFile$Year >= yYear & dataFile$Year <= (yYear+2) & dataFile$CC2 == C,], ylim=c(-201,279),xlim=c(-265,215),col=myColors[C],pch=mySymbols[C],bg="transparent") dev.off() } } } } par(opar) #restore pars }