## Transparent colors ## Mark Gardener 2015 ## www.dataanalytics.org.uk t_col <- function(color, percent = 75, name = NULL) { # color = color name # percent = % transparency # name = an optional name for the color ## Get RGB values for named color rgb.val <- col2rgb(color) ## Make new color using input color as base and alpha set by transparency t.col <- rgb(rgb.val[1], rgb.val[2], rgb.val[3], max = 255, alpha = (100-percent)*255/100, names = name) ## Save the color invisible(t.col) } ## END plotCI <- function(estimate, lower, upper, col){ matplot } library(sp) library(rgdal) library(RColorBrewer) library(classInt) expit<-function(x){ exp(x)/(1+exp(x)) } logit<-function(x){ log(x/(1-x)) } source("http://www.math.mcmaster.ca/bolker/R/misc/legendx.R") plotHatch = function(regPred, zLim, sdLim, breaks, ticks, regMap){ nHatch = 4 # breaks = exp(seq(log(sdLim[1]), log(sdLim[2]), length.out = nHatch +1)) # breaks = round(breaks, 2) nCol = 64 sdLim = c(breaks, 1e100) med.palette = viridis(nCol) med.int = (log(regPred$med)-log(zLim[1]))/diff(log(zLim))*64 med.col = med.palette[floor(med.int)] plot(regMap, lwd = 1.5, col = med.col, axes = TRUE, xlab = "Longitude", ylab = "Latitude", cex.axis = 1.5, cex.lab = 1.5, bty= "l") image.plot(legend.only = TRUE, zlim = log(zLim), legend.mar = 7.5, axis.args = list(cex.axis = 1.5, at = log(ticks), labels =ticks ), col = viridis(64)) for(j in 1:length(regMap$NAME_1)){ per = regPred$sd[j]/regPred$med[j]*100 den.idx = which.max(per < sdLim) for(i in 1:length(regMap@polygons[[j]]@Polygons)) polygon(regMap@polygons[[j]]@Polygons[[i]]@coords, density = 10*(den.idx-2), border = FALSE, lwd = 1.5) } legend(x = 'bottomleft', inset = 0, legend = c(paste('[', sdLim[1], '%, ', sdLim[2], '%)', sep = ""), paste('[', sdLim[2], '%, ', sdLim[3], '%)', sep = ""), paste('[', sdLim[3], '%, ', sdLim[4], '%)', sep = ""), paste('[', sdLim[4], '%, ', sdLim[5], '%)', sep = ""), paste('> ', sdLim[5], '%', sep = "")), col = rep('black',2), cex = 1.25, box.cex = c(2,1), density = c(0, 10,20,30, 40), bty = 'n') }