Skip to content

Instantly share code, notes, and snippets.

View jebyrnes's full-sized avatar

Jarrett Byrnes jebyrnes

View GitHub Profile
@jebyrnes
jebyrnes / rethinking_errors.R
Created February 17, 2016 13:47
variable residual errors in rethinking
make_data <- function(slope =1, int = 1, sd_e = 5, group=1, x=1:20){
ret <- data.frame(x=x)
ret <- within(ret, {
y <- rnorm(length(x), int + slope*x, sd_e)
group <- group
})
ret
}
library(nlme)
library(ggplot2)
library(lubridate)
library(dplyr)
#download data from https://www.google.com/trends/explore#q=%22i%20cant%20even%22&cmpt=q&tz=Etc%2FGMT%2B5
i_cant_even <- read.csv("./i_cant_even.csv", skip=4)
#reformat weeks
i_cant_even$Week <- as.character(i_cant_even$Week)
@jebyrnes
jebyrnes / leafletMapWithLegend.R
Last active August 29, 2015 14:19
A demo of leaflet using a color legend
#devtools::install_github("rstudio/leaflet", ref="feature/color-legend")
library(leaflet)
library(RColorBrewer)
set.seed(100)
pdf <- data.frame(Latitude = runif(100, -90,90), Longitude = runif(100, -180,180))
#make a property with colors
pdf$Study <- rep(1:10,10)
#need to create a pal using colorbin
@jebyrnes
jebyrnes / leafletMap.R
Last active August 8, 2022 14:13
Basic leaflet mapping in R
#Load the library and make a basic map
library(leaflet)
leaflet() %>% addTiles()
#Show a map with a satellite picture on it
leaflet() %>%
addTiles(urlTemplate="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}")
#Make a demo fake data set
@jebyrnes
jebyrnes / meow_plot_base.R
Last active November 25, 2020 04:10
Basic methods for dealing with shapefiles for marine ecoregions of the world.
#########################################################################
# Code to import and make useful
# Spalding et al. 2007's Marine Ecoregions of the World
# Data provided by http://www.marineregions.org/downloads.php
# by Jarrett Byrnes
# last updated 3/26/2015
#########################################################################
######################
##### Load Libraries
@jebyrnes
jebyrnes / scatterPlot3d.R
Last active August 29, 2015 14:10
Plotting in 3D in R
#just create a range of values
grdVals <- function(x, bound=0.01) seq(range(x)[1]-bound, range(x)[2]+bound, length.out=50)
#instantiate a new persp object for a scatterplot
makeScatterBox <- function(x,y,z, bound=0, ...){
x <- grdVals(x, bound=bound)
y <- grdVals(y, bound=bound)
z <- grdVals(z, bound=bound)
z <- matrix(rep(z, 50), nrow=50)
@jebyrnes
jebyrnes / dcov.test
Created October 23, 2014 19:09
misbehaving_dcov.Rnw
\documentclass{article}
\begin{document}
<<echo=FALSE>>=
activityDF <- structure(list(julian_day = 1:365, food = c(92.6182247978374,
199.361820535986, 128.619308542186, 131.048504694701, 44.6344539529983,
139.02542881751, 118.815437972886, 85.5963235153311, 73.9459098960665,
85.6671795660157, 195.954639346317, 192.942941724749, 193.341526021202,
142.419581610027, 130.23002915561, 232.843857188757, 105.14817987285,
131.58751463704, 123.30056211349, 150.447279408636, 138.40775613945,
library(multifunc)
data(all_biodepth)
allVars<-qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3)
germany<-subset(all_biodepth, all_biodepth$location=="Germany")
vars<-whichVars(germany, allVars)
#re-normalize N.Soil so that everything is on the same sign-scale (e.g. the maximum level of a function is the "best" function)
germany$N.Soil<- -1*germany$N.Soil +max(germany$N.Soil, na.rm=TRUE)
@jebyrnes
jebyrnes / getSpaldingRegions.R
Created June 10, 2014 17:50
Script to get Spalding's Marine Ecoregions of the World in R from lat/long data and a GIS file.
############################################################################################
#
# Script to turn lat/long data into
# marine ecoregions using Spalding's Marine Ecoregions
# of the World (MEOW).
#
# To run, first acquire the appropriate GIS files from
# http://maps.tnc.org/gis_data.html and unzip them into
# a directory (MEOW-TNC) - then go from there.
#
@jebyrnes
jebyrnes / germany_biodepth_zissou.R
Created March 31, 2014 21:25
A multifunctionality analysis using the threshold effect for Biodepth in Germany using the Zissou color scheme from Karthik's wesanderson package for color palates.
library(multifunc)
library(wesanderson)
data(all_biodepth)
allVars<-qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3)
germany<-subset(all_biodepth, all_biodepth$location=="Germany")
vars<-whichVars(germany, allVars)
#re-normalize N.Soil so that everything is on the same sign-scale (e.g. the maximum level of a function is the "best" function)