Skip to content

Instantly share code, notes, and snippets.

View jebyrnes's full-sized avatar

Jarrett Byrnes jebyrnes

View GitHub Profile
@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 / 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
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 / 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
}
@jebyrnes
jebyrnes / conditional_independence_dcov.R
Created March 28, 2016 17:00
A simulation to look at how distance based correlation can work with D-sep tests
#############
#' @title Fisher's C and Distance Correlation
#'
#' @author Jarrett Byrnes
#'
#' @description A simulation to look at
#' how distance based correlation can work with
#' D-sep tests
#'
#############
library(dplyr)
library(ggplot2)
library(meowR); data(regions)
library(sp)
kelp <- read.csv("../01_clean_raw_data/temporal_data_REBENT_Brittany_NW_France.csv")
#Create a spatial Points Data Frame
@jebyrnes
jebyrnes / had_crut_spider_plot.R
Created May 13, 2016 18:40
R code to reproduce the awesome visualization of global temperature change from Ed Hawkins at http://www.climate-lab-book.ac.uk/2016/spiralling-global-temperatures/ using R and ggplot2 (with the animations package)
library(dplyr)
library(tidyr)
library(ggplot2)
library(animation)
#Data from https://crudata.uea.ac.uk/cru/data/temperature/
#As well as data read in script
source("read_cru_hemi.R")
temp_dat <- read_cru_hemi("./HadCRUT4-gl.dat")
#remove cover
@jebyrnes
jebyrnes / testFrame.R
Last active September 26, 2016 13:34
testFrame <- structure(list(Year = c(1948, 1949, 1950, 1951, 1952), `X_-177_52` = c(18.9220237749285,
21.8483886536779, 18.620676780609, 27.0751608868709, 32.4921595618974
), `X_-172.5_52` = c(31.9994862200926, 38.5639899672935, 31.836112737235,
42.7914952437946, 53.1652576093285), `X_-168_53` = c(26.226590342774,
35.5284697356814, 26.2798166889216, 37.5791359982477, 45.5915562248318
), `X_-136.5_58` = c(24.7796363128934, 24.5255804518598, 16.5003662047736,
23.5168277681755, 32.9788961278221), `X_-132_53` = c(19.5107068615539,
19.6662279616348, 16.0907033411067, 19.1839879174579, 24.0906788816321
), `X_-130.5_52` = c(25.4554902780508, 27.105312123341, 25.5231126523454,
25.9769619101539, 33.7769913419713), `X_-127.5_50` = c(31.9535070030102,
@jebyrnes
jebyrnes / casey_mixed_mod_power.R
Created October 1, 2016 22:20
An a priori power analysis of a mixed model design from the terHorst lab. Just for fun.
#Some libraries that will help
library(nlme)
library(dplyr)
library(tidyr)
library(mvtnorm)
######This controls it all!
n_sims <- 5
#A function to make a sigma matrix
@jebyrnes
jebyrnes / rethinking_measurement_errors.R
Created November 27, 2016 15:43
Rethinking Measurement Error - models using the rethinking package that incorporate measurement in both the response and predictor variables.
library(rethinking)
library(dplyr)
data(WaffleDivorce)
mod <- alist(
#likelihood
div_est ~ dnorm(mu, sigma),
#model