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
# load libraries | |
library(sp) # for meuse | |
library(sf) # for sf objects | |
library(ggmap) # for base maps | |
library(ggplot2) # for mapping | |
# import dataset, check structure | |
data(meuse) | |
str(meuse) |
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
#import relevant packages | |
library(gstat) | |
library(sp) | |
library(nlme) | |
#create simulated data, lat and lon from uniformly distributed variable, exp1 and exp2 from random normal | |
set.seed(2) | |
samp.sz<-400 | |
lat<-runif(samp.sz,-4,4) | |
lon<-runif(samp.sz,-4,4) |
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
mc.int.ex<-function(x.range=c(-3,3),int=c(-1.96,1.96),n=10000,plot=T, | |
plot.pts=T,plot.poly=T,cols=list('black','green','blue'),round.val=2,val=F){ | |
require(scales) | |
#create data for model fit | |
x.fit<-seq(x.range[1],x.range[2],length=n) | |
y.fit<-dnorm(x.fit) | |
dat.fit<-data.frame(x.fit,y.fit) | |
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
#credit http://stackoverflow.com/questions/13649473/add-a-common-legend-for-combined-ggplots | |
require(ggplot2) | |
require(reshape) | |
require(gridExtra) | |
p.dat<-data.frame(step=row.names(grp.dat),grp.dat,stringsAsFactors=F) | |
p.dat<-melt(p.dat,id='step') | |
p.dat$step<-as.numeric(p.dat$step) |
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
#' Format a text file for mothur | |
#' | |
#' @param fl chr string for input file | |
#' @param rev_cmp logical if file needs reverse complemeNT | |
#' @param savefl logical if output file is saved, otherwise the output is returned in the console | |
moth_form <- function(fl, rev_cmp = FALSE, savefl = TRUE, flnm = 'myfile.txt'){ | |
# import file | |
dat <- read.table(fl, sep = '\t') | |
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
plotFlowConc <- function(eList, month = c(1:12), years = NULL, col_vec = c('red', 'green', 'blue'), ylabel = NULL, xlabel = NULL, alpha = 1, size = 1, allflo = FALSE, ncol = NULL, grids = TRUE, scales = NULL, interp = 4, pretty = TRUE, use_bw = TRUE, fac_nms = NULL, ymin = 0){ | |
localDaily <- getDaily(eList) | |
localINFO <- getInfo(eList) | |
localsurfaces <- getSurfaces(eList) | |
# plot title | |
toplab <- with(eList$INFO, paste(shortName, paramShortName, sep = ', ')) | |
# flow, date info for interpolation surface |
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.qual<-function(x,x.locs=c(0.01,0.99),y.locs=c(0,1),steps=NULL,sp.names=NULL,dt.tx=T,rsc=T, | |
ln.st=NULL,rs.ln=c(3,15),ln.cl='RdYlGn',alpha=0.7,leg=T,rnks=FALSE,...){ | |
require(RColorBrewer) | |
require(scales) | |
if(length(x.locs) != 2 | length(y.locs) != 2) | |
stop('x and y dimensions must be two-element vectors') | |
if(x.locs[1]<0 | x.locs[2]>1 | y.locs[1]<0 | y.locs[2]>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
# PPOTM: Practical-Programming Of The Month (2016 January) | |
# iMAINloop: Continue asking users "what file to load" until they type a zero. | |
iMAINloop <- 0; | |
while (iMAINloop < 1 ) { | |
# Below creates a list of all files (in the current working directory) of pattern *.csv | |
# Note that you can set path="xxxx" to look in a different folder area | |
filenames <- list.files(pattern = ".csv") |
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
lek.fun<-function(mod.in,var.sens=NULL,resp.name=NULL,exp.in=NULL,steps=100,split.vals=seq(0,1,by=0.2),val.out=F){ | |
require(ggplot2) | |
require(reshape) | |
## | |
#sort out exp and resp names based on object type of call to mod.in | |
#get matrix for exp vars | |
#for nnet |
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.area<-function(x,col=NULL,horiz=F,prop=T,stp.ln=T,grp.ln=T,axs.cex=1,axs.lab=T,lab.cex=1, | |
names=c('Group','Step','Value'),...){ | |
#sort out color fector | |
if(!is.null(col)){ | |
if(sum(col %in% colors()) != length(col)) stop('col vector must be in "colors()"') | |
col<-colorRampPalette(col)(ncol(x)) | |
} | |
else col<-colorRampPalette(c('lightblue','green'))(ncol(x)) | |