This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
makeGlobcolourField <- function( | |
dataPath=getwd(), | |
yearRan=c(1997,2013), | |
lonRan=c(-83,-79), | |
latRan=c(-16,-4), | |
greps=c(".nc", "GSM", "MO") | |
){ | |
#Import data | |
grd <- list() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(devtools) | |
source_url('https://gist.github.com/menugget/7689145/raw/dac746aa322ca4160a5fe66c70fec16ebe26faf9/image.scale.2.r') | |
source_url('https://gist.github.com/menugget/7864454/raw/f698da873766347d837865eecfa726cdf52a6c40/plot.stream.4.R') | |
source_url('https://gist.github.com/menugget/7864471/raw/8127dfaae183233d203580bc247a73a564d5feab/plot.stacked.2.R') | |
set.seed(1) | |
m <- 500 | |
n <- 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#plot.stacked makes a stacked plot where each y series is plotted on top | |
#of the each other using filled polygons | |
# | |
#Arguments include: | |
#'x' - a vector of values | |
#'y' - a matrix of data series (columns) corresponding to x | |
#'order.method' = c("as.is", "max", "first") | |
# "as.is" - plot in order of y column | |
# "max" - plot in order of when each y series reaches maximum value | |
# "first" - plot in order of when each y series first value > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#plot.stream makes a "stream plot" where each y series is plotted | |
#as stacked filled polygons on alternating sides of a baseline. | |
# | |
#Arguments include: | |
#'x' - a vector of values | |
#'y' - a matrix of data series (columns) corresponding to x | |
#'order.method' = c("as.is", "max", "first") | |
# "as.is" - plot in order of y column | |
# "max" - plot in order of when each y series reaches maximum value | |
# "first" - plot in order of when each y series first value > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(devtools) | |
source_url('https://gist.github.com/menugget/7689145/raw/dac746aa322ca4160a5fe66c70fec16ebe26faf9/image.scale.2.r') | |
png("volcano_w_scale.png", width=7, height=4, units="in", res=200) | |
layout(matrix(c(1,2,3,0,4,0), nrow=2, ncol=3), widths=c(4,4,1), heights=c(4,1)) | |
layout.show(4) | |
#1st image | |
breaks <- seq(min(volcano), max(volcano),length.out=100) | |
par(mar=c(1,1,1,1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This function reconstructs a data set using a defined set of principal components. | |
#arguments "pca" is the pca object from prcomp, "pcs" is a vector of principal components | |
#to be used for reconstruction (default includes all pcs) | |
prcomp.recon <- function(pca, pcs=NULL){ | |
if(is.null(pcs)) pcs <- seq(pca$sdev) | |
recon <- as.matrix(pca$x[,pcs]) %*% t(as.matrix(pca$rotation[,pcs])) | |
if(pca$scale[1] != FALSE){ | |
recon <- scale(recon , center=FALSE, scale=1/pca$scale) | |
} | |
if(pca$center[1] != FALSE){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this function converts a vector of values("z") to a vector of color | |
#levels. One must define the number of colors. The limits of the color | |
#scale("zlim") or the break points for the color changes("breaks") can | |
#also be defined. when breaks and zlim are defined, breaks overrides zlim. | |
val2col<-function(z, zlim, col = heat.colors(12), breaks){ | |
if(!missing(breaks)){ | |
if(length(breaks) != (length(col)+1)){stop("must have one more break than colour")} | |
} | |
if(missing(breaks) & !missing(zlim)){ | |
zlim[2] <- zlim[2]+c(zlim[2]-zlim[1])*(1E-3)#adds a bit to the range in both directions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This function creates a color scale for use with the image() | |
#function. Input parameters should be consistent with those | |
#used in the corresponding image plot. The "axis.pos" argument | |
#defines the side of the axis. The "add.axis" argument defines | |
#whether the axis is added (default: TRUE)or not (FALSE). | |
image.scale <- function(z, zlim, col = heat.colors(12), | |
breaks, axis.pos=1, add.axis=TRUE, ...){ | |
if(!missing(breaks)){ | |
if(length(breaks) != (length(col)+1)){stop("must have one more break than colour")} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bv.step <- function(fix.mat, var.mat, | |
fix.dist.method="bray", var.dist.method="euclidean", | |
scale.fix=FALSE, scale.var=TRUE, | |
max.rho=0.95, | |
min.delta.rho=0.001, | |
random.selection=TRUE, | |
prop.selected.var=0.2, | |
num.restarts=10, | |
var.always.include=NULL, | |
var.exclude=NULL, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bio.env <- function(fix.mat, var.mat, | |
fix.dist.method="bray", var.dist.method="euclidean", | |
scale.fix=FALSE, scale.var=TRUE, | |
output.best=10, | |
var.max=ncol(var.mat) | |
){ | |
if(dim(fix.mat)[1] != dim(var.mat)[1]){stop("fixed and variable matrices must have the same number of rows")} | |
if(var.max > dim(var.mat)[2]){stop("var.max cannot be larger than the number of variables (columns) in var.mat")} | |
require(vegan) |
NewerOlder