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)
# 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
@SwampThingPaul
SwampThingPaul / StatsTests101.r
Created October 6, 2019 20:48
Weekend of a Data Scientist in R
# R version of https://medium.com/cindicator/must-have-statistical-tests-for-any-data-scientist-weekend-of-a-data-scientist-4543f2c393cd
# Medium Article written by Alexander Osipenko (https://medium.com/@subpath)
# Fake Data (not the same data as article)
set.seed(123)
groupA=rnorm(1000)
groupB=rnorm(1100,mean=0.001)
# Quick Density plot