Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Julian SwampThingPaul

View GitHub Profile
@SwampThingPaul
SwampThingPaul / ExtractPaletteColors.R
Created Sep 7, 2020
Code to extract colors from an image based on k-means
View ExtractPaletteColors.R
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
A working example with data of ggridges
View ggridges_example.r
## 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 Mar 27, 2020
Strobl and Robillard (2008) samples per year
View SampleSize_Monitoring.r
# 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)
View quick_bar_line.r
## 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 Feb 15, 2020
check and install packages
View package_install.r
## 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 Feb 4, 2020
Data, replicated analyses/plots and other trend tests in r
View Reckhowetal_trend.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
Created Jan 6, 2020
A scale-able, reproducible example of boxplot definition.
View boxplot_example.r
# 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)
View CERF2019_TweetQuery.r
##
## Code was compiled by Paul Julian
## contact info: pauljulianPhD@gmail.com
# Some helpful sites
#https://rtweet.info
#https://www.johnlittle.info/project/custom/rtweet/network_graph_more_examples.nb.html
#https://www.earthdatascience.org/courses/earth-analytics/get-data-using-apis/use-twitter-api-r/
#http://www.rdatamining.com/docs/twitter-analysis-with-r
@SwampThingPaul
SwampThingPaul / plot.lm.fun.R
Last active Oct 23, 2019
Linear model diagnostic plots i.e. hacking plot.lm(...)
View plot.lm.fun.R
##
## Code was compiled by Paul Julian
## contact info: pjulian@ufl.edu
##
## Example of how to hack plot.lm
#devtools::install_github("SwampThingPaul/AnalystHelper")
library(AnalystHelper)
#for color maps
@SwampThingPaul
SwampThingPaul / StatsTests101.r
Created Oct 6, 2019
Weekend of a Data Scientist in R
View StatsTests101.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
You can’t perform that action at this time.