Skip to content

Instantly share code, notes, and snippets.

View SwampThingPaul's full-sized avatar

Paul Julian SwampThingPaul

View GitHub Profile
@SwampThingPaul
SwampThingPaul / juliandates.r
Created June 23, 2021 13:37
Conversion of julian and calendar dates
# Functions from a seperate python script
# Calendar to Julian Days
cal2jd=function(date){
year=as.numeric(format(date,"%Y"))
month=as.numeric(format(date,"%m"))
day=as.numeric(format(date,"%d"))
a = (14 - month)/12
y = year + 4800 - a
m = month + 12*a - 3
@SwampThingPaul
SwampThingPaul / Lake_VolArea.r
Last active May 24, 2021 16:11
Lake Volume and Area Calculation
## Code was compiled by Paul Julian
## contact info: pauljulianphd@gmail.com
# GIS libraries
library(sp)
library(rgdal)
library(rgeos)
library(raster)
# projection
@SwampThingPaul
SwampThingPaul / as_flextable_GAM.r
Created January 8, 2021 15:54
GAM version of as_flextable
## A series of functions to extract and display model summary tables
## Generalized Additive Models
## Code was compiled by Paul Julian
## contact info: pauljulianphd@gmail.com
## libraries
library(mgcv)
library(flextable)
library(magrittr)
@SwampThingPaul
SwampThingPaul / ExtractPaletteColors.R
Created September 7, 2020 18:49
Code to extract colors from an image based on k-means
library(jpeg)
# Custom function similar to print.palette(...)
RenderPal <- function(x,name){
if ((missing(x)) || (missing(name))){
stop("Internal error, please troubleshoot")
}
n <- length(x)
old <- graphics::par(mar = c(0.5, 0.5, 0.5, 0.5))
@SwampThingPaul
SwampThingPaul / ggridges_example.r
Created May 29, 2020 12:21
A working example with data of ggridges
## A working example with data of ggridges
# Libraries ---------------------------------------------------------------
if(!require(ggplot2)) { install.packages('ggplot2') } ; library(ggplot2)
if(!require(ggridges)) { install.packages('ggridges') } ; library(ggridges)
# Data --------------------------------------------------------------------
dat=data.frame(FedWY=c(1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979,
1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979,
1979, 1979, 1979, 1979, 1979, 1979, 1980, 1980, 1980, 1980, 1980,
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980,
@SwampThingPaul
SwampThingPaul / SampleSize_Monitoring.r
Last active March 27, 2020 00:59
Strobl and Robillard (2008) samples per year
# From
## Strobl, R.O., Robillard, P.D., 2008. Network design for water
## quality monitoring of surface freshwaters: A review. Journal
## of Environmental Management, Microbial and Nutrient Contaminants
## of Fresh and Coastal Waters 87, 639–648.
## https://doi.org/10.1016/j.jenvman.2007.03.001
#devtools::install_github("SwampThingPaul/AnalystHelper")
library(AnalystHelper)
## quick bar and line plot in base
data=data.frame(value=c(3,4,6,2),value2=c(10,12,20,9))
par(oma=c(3,2,0.5,3),mar=c(2,3,0.25,2))
barplot(data$value,ylim=c(0,12),las=2,space=c(0.5))
mtext(side=2,line=2,"Value")
par(new=T);x=barplot(data$value2,ylim=c(0,25),axes=F,col=NA,border=NA,space=c(0.5))
lines(x,data$value2,lwd=3)
axis(4,las=2)
@SwampThingPaul
SwampThingPaul / package_install.r
Created February 15, 2020 01:55
check and install packages
## Function to check and install packages
## If package is installed, then the function moves to the next.
check.packages <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
@SwampThingPaul
SwampThingPaul / Reckhowetal_trend.r
Created February 4, 2020 18:01
Data, replicated analyses/plots and other trend tests in r
## Data from Reckhow, K.H., K Kepford and W.W. Hicks. 1993
### Methods for the Analysis of Lake Water Quality
### EPA 841-R-93-003
## Code was compiled by Paul Julian
## contact info: paul.julian@floridadep.gov
@SwampThingPaul
SwampThingPaul / boxplot_example.r
Last active April 22, 2026 13:06
A scale-able, reproducible example of boxplot definition.
# Base curly brackets adapted from https://stackoverflow.com/a/9310002/5213091
CurlyBraces <- function(x, y, min.val,max.val, pos = 1, direction = 1 ,b=c(0,.2,.28,.7,.8),a=c(1,2,3,48,50)) {
# a set flexion point for spline
# b set depth for spline flexion point
curve <- spline(a, b, n = 50, method = "natural")$y / 2
curve <- c(curve,rev(curve))
a_sequence <- rep(x,100)