<% library(rgdal) library(rgeos) library(gstat) library(lattice) library(RSAGA) library(maptools) library(akima) library(Cairo) library(classInt) library(RColorBrewer) library(sp) # library(ggmap) # library(ggplot2) # setwd('/var/www/R/mkclimate/polys') impdata <- read.table('/var/www/R/Rtmp/ClimaticDataMK.txt', header = T, sep = '\t') # boundaryState <- readOGR(".","mk_boundary") # boundaryState <- spTransform(boundaryState, CRS("+proj=longlat +datum=WGS84")) # variable names datatype <- "Precipitation" pltlabel <- "Precipitation (mm)" mname <- "January" if(!is.null(POST)) { datatype <- as.character(POST$Data) if(datatype == "Precipitation") { pltlabel <- "Precipitation (mm)" } else if (datatype == "Temperature") { pltlabel <- expression(paste("Temperature (",degree,"C)")) } else if (datatype == "Relative Humidity") { pltlabel <- "Relative Humidity (%)" } else { pltlabel <- "Wind Speed (m/s)" } mname <- as.character(POST$Month) } mkdata <- subset(impdata , impdata$DataType == datatype) coordinates(mkdata) <- ~LONG+LAT proj4string(mkdata) <- CRS("+proj=longlat +datum=WGS84") mkdatall <- mkdata # fnametmp <- tempfile(tmpdir='/var/www/tmp', "", fileext=".kml") # fname <- paste("http://geogis.bgsu.edu/tmp/", '', basename(fnametmp), sep='') # maxvar <- max(mkdatall[mname]@data) # maximum value # filename <- file(paste(fnametmp, sep=""), "w", blocking=FALSE) bppng <- paste(tempfile(pattern = "png_", tmpdir='/var/www/tmp'), '.png', sep='') histpng <- paste(tempfile(pattern = "png_", tmpdir='/var/www/tmp'), '.png', sep='') hpng <- paste(tempfile(pattern = "png_", tmpdir='/var/www/tmp'), '.png', sep='') quantpng <- paste(tempfile(pattern = "png_", tmpdir='/var/www/tmp'), '.png', sep='') if (!file.exists(bppng)){ CairoPNG(filename=bppng,width=495,height=490) newdata <- mkdatall Lon <- mkdatall$LONG Lat <- mkdatall$LAT mesec <- mkdatall[[mname]] newdata <- cbind.data.frame(Lon, Lat, mesec) colnames(newdata) <- c("LONG", "LAT", mname) coordinates(newdata) <- c("LONG", "LAT") class(newdata) title_new = paste("Total Rainfall for ", mname) maxrain <- max(newdata[[mname]]) print(bubble(newdata, mname, main = title_new, sub = "Rainfall (mm); symbol size proportional to value", col = "limegreen", scales = list(draw = TRUE), maxsize = 2.0, fill = F, xlab = "Lon", ylab = "Lat", sizelab = "Y (m)", xlim = c(40.8138, 42.4072), ylim = c(20.3796, 23.1097), aspect = "iso", panel = function(x,y, ...) { panel.xyplot(x, y, ...) panel.grid(h = -1, v = -1, col = "purple4", lty = 2) }, key.entries = seq(0, maxrain, by = 10))) dev.off() } if (!file.exists(histpng)){ CairoPNG(filename=histpng,width=495,height=490) plotdata <- mkdatall[mname]@data month <- names(plotdata) nf <- layout(mat = matrix(c(1,2),2,1, byrow=TRUE), height = c(1,3)) par(mar=c(5.1, 4.5, 0.5, 2.1)) boxplot(plotdata[[month]], horizontal=TRUE ) h <- hist(plotdata[[month]], breaks=8, col="grey", main="", xlab=pltlabel, cex.lab =1.4) xfit<-seq(min(mkdatall[[month]]),max(mkdatall[[month]]),length=40) yfit<-dnorm(xfit,mean=mean(mkdatall[[month]]),sd=sd(mkdatall[[month]])) yfit <- yfit*diff(h$mids[1:2])*length(mkdatall[[month]]) lines(xfit, yfit, col="blue", lwd=2) dev.off() } if (!file.exists(hpng)){ CairoPNG(filename=hpng,width=495,height=490) plotdata <- mkdatall[mname]@data month <- names(plotdata) # interpolation Lon <- mkdatall$LONG Lat <- mkdatall$LAT # restrict to 4 blocks sw <- subset(mkdatall, 41 <= Lat & Lon >= 20.5 & 41.6 >= Lat & Lon <= 21.7) nw <- subset(mkdatall, 41.6 <= Lat & Lon >= 20.5 & 42.2 >= Lat & Lon <= 21.7) ne <- subset(mkdatall, 41.6 <= Lat & Lon >= 21.7 & 42.2 >= Lat & Lon <= 22.9) se <- subset(mkdatall, 41 <= Lat & Lon >= 21.7 & 41.62 >= Lat & Lon <= 22.9) hp <- layout(mat = matrix(c(1,2,3,4),2,2, byrow=TRUE), height = c(2,2)) par(oma=c(5,5,5,5), mar=c(3,3,0.5,0.5)) swh <- hist(sw[[month]], prob=1, main="", xlab="", ylab="") lines(density(sw[[month]],kernel="gaussian"),col=2) nwh <- hist(nw[[month]], prob=1, main="", xlab="", ylab="") lines(density(nw[[month]],kernel="gaussian"),col=2) neh <- hist(ne[[month]], prob=1, main="", xlab="", ylab="") lines(density(ne[[month]],kernel="gaussian"),col=2) seh <- hist(se[[month]], prob=1, main="", xlab="", ylab="") lines(density(se[[month]],kernel="gaussian"),col=2) box("inner", col="black") mtext(c("20.5", "21.7", "22.9"), side=1, at=c(0.05, 0.48, 0.95), line=0.5, adj=0.0, cex=1, col="black", outer=TRUE) mtext(c("|", "|", "|"), side=1, at=c(0.07, 0.5, 0.97), line=-0.4, adj=0.0, cex=0.6, col="black", outer=TRUE) mtext("Longitude", side=1, line=2.3, cex=1.4, col="black", outer=TRUE) mtext(c("41.0", "41.6", "42.2"), side=2, at=c(0.01, 0.47, 0.95), line=0.5, adj=0.0, las=0, cex=1, col="black", outer=TRUE) mtext(c("|", "|", "|"), side=2, at=c(0.03, 0.497, 0.97), line=-0.1, adj=0.0, cex=0.6, col="black", outer=TRUE) mtext("Latitude", side=2, line=2.3, cex=1.4, col="black", outer=TRUE) mtext("Conditional Plot", side=3, line=1, cex=1.5, col="black", outer=TRUE) dev.off() } if (!file.exists(quantpng)){ CairoPNG(filename=quantpng,width=495,height=490) plotdata <- mkdatall[mname]@data month <- names(plotdata) pal <- brewer.pal(3, "Blues") q5 <- classIntervals(plotdata[[month]], n = 5, style = "quantile") plot(q5, pal = pal, main ="Quantile Plot", ylab = "", xlab = pltlabel) dev.off() } bpfname <- paste("http://geogis.bgsu.edu/tmp/", '', basename(bppng), sep='') histfname <- paste("http://geogis.bgsu.edu/tmp/", '', basename(histpng), sep='') hfname <- paste("http://geogis.bgsu.edu/tmp/", '', basename(hpng), sep='') quantfname <- paste("http://geogis.bgsu.edu/tmp/", '', basename(quantpng), sep='') %> Climatic Data

Macedonia Climate Averages: <% cat(datatype ) %> for <% cat(mname) %> (1961 - 1990)


Select Data

Climatic Data:

Select Month: