Skip to content

Instantly share code, notes, and snippets.

View SwampThingPaul's full-sized avatar

Paul Julian SwampThingPaul

View GitHub Profile
@SwampThingPaul
SwampThingPaul / StickplotArrows.r
Last active February 27, 2019 13:07
Wind Speed Stick Plot
stickplot.arrows=function(DateTime,WSPD,WD,data,...){
require(lubridate)
#DateTime = Date and Time in POSIXct format (also works with just dates)
#WSPD = Wind Speed in velocity units (i.e. m/s)
#WD = Wind direction in degrees
if(!missing(data)){
DateTime=data[,deparse(substitute(DateTime))]
WSPD=data[,deparse(substitute(WSPD))]
WD=data[,deparse(substitute(WD))]
@SwampThingPaul
SwampThingPaul / plot_example_range.R
Created April 7, 2019 19:14
Showing variability in a data set using base plotting
#Some Example data
library(dataRetrieval)
sdate="1979-10-01"
edate="2010-12-31"
site="02298830"
param="00060"
dat=readNWISdv(site,param,sdate,edate)
#Data manipulation
@SwampThingPaul
SwampThingPaul / Reiger_Cusum.r
Last active April 18, 2019 12:30
R-equivalent of the Cusum metric developed by Reiger et al.
# Developed based on the ideas Regier et al (2019) Analyzing and comparing
## complex environmental time series using a cumulative sums approach.
## MethodsX 6:779–787. doi: 10.1016/j.mex.2019.03.014
#
# Link to paper:
## https://www.sciencedirect.com/science/article/pii/S2215016119300597?via%3Dihub
test=c(seq(1,10),rev(seq(1,10)))
cusum=round(cumsum(base::scale(test)),1)
@SwampThingPaul
SwampThingPaul / DOWY_stats.r
Last active April 26, 2019 13:23
Hydrologic Data-vis example
##
## Hydrologic data visualization
##
## Code was compiled by Paul Julian
## contact infor: pjulian@ufl.edu
#Clears Everything...start fresh.
rm(list=ls(all=T));cat("\014");dev.off()
#Libraries
##
## Evaluating the potential dilution of variance in long term data
## DOI 10.17605/OSF.IO/RPBTS
## https://osf.io/rpbts
##
## Code was compiled by Paul Julian
## contact infor: pjulian@ufl.edu
library(cumstats)
@SwampThingPaul
SwampThingPaul / colorgrad.r
Created May 28, 2019 12:38
Base plotting with color gradient (continuous and discrete) and point size gradient.
##
##
## Example of color ramp gradient legend in base R
##
##
## Code was compiled by Paul Julian
## contact info: pjulian@ufl.edu
##
## code adpated from several sources including
# https://stackoverflow.com/questions/25001542/coloring-the-points-in-a-plot-based-on-another-numeric-variable
library(sp)
library(rgdal)
utm15=CRS("+proj=utm +zone=15 +datum=WGS84 +units=m")
wgs84=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
# convert to shapefile
sp.tribnames=SpatialPointsDataFrame(coords=tribnames[,c("EASTING","NORTHING")],data=tribnames,proj4string = utm15)
plot(sp.tribnames)
sp.tribnames=spTransform(sp.tribnames,wgs84)
## UTS/South Dade Rainfall discharge
##
## Code was compiled by Paul Julian
## contact info: pjulian@ufl.edu
#Libraries
library(AnalystHelper);#devtools::install_github("SwampThingPaul/AnalystHelper")
library(plyr)
library(reshape)
@SwampThingPaul
SwampThingPaul / example_plots.r
Last active October 6, 2021 12:22
Example plots of how different regressions are estimated. Essentially reproducing Fig 4 in Warton et al (2006)
## From https://tonyladson.wordpress.com/2020/10/05/errors-in-variables-regression/
## Code adapted from https://gist.github.com/TonyLadson/286077221cc07022a77aa74d0a6c211c
# Libraries
library(deming)
# Functions ---------------------------------------------------------------
# given a point (x1, y1) and a line defined by a slope m and intercept c1
# R version of https://towardsdatascience.com/p-value-explained-simply-for-data-scientists-4c0cd7044f14
# Towards Data Science Article written by Rahul Agarwal (https://towardsdatascience.com/@rahul_agarwal)
# WeightLoss Sample Mean (kg)
mu=2
# Sample Standard Deviation (kg)
sigma=1
## Probability