Skip to content

Instantly share code, notes, and snippets.

View hannahlowens's full-sized avatar

Hannah Owens hannahlowens

View GitHub Profile
@hannahlowens
hannahlowens / SupportingInformationMEE_2023
Last active August 4, 2023 13:18
This script was used to run analysis and generate figures for Owens and Rahbek, 2023 in Methods in Ecology and Evolution. NOTE: This is a legacy script that will not work when RGDAL is deprecated in fall 2023. The voluModel package has been updated and does not depend on rgdal or raster.
# voluModel Methods in Ecology and Evolution Code Supplement
# R version: 4.1.2 (2021-11-01)
# Platform: x86_64-apple-darwin17.0
#
# Figure 1 ----
library(voluModel) # Because of course
library(ggplot2) # For fancy plotting
library(rgdal) # For vector stuff. Will eventually be replaced with sf.
library(raster) # For raster stuff. Will eventually be replaced with terra.
library(viridisLite) # For high-contrast plotting palettes
@hannahlowens
hannahlowens / PaleoClimateProcessing.R
Last active August 4, 2023 13:16
Processing monthly paleoclimate model data into 1,000 year climatologies for Bio1, Bio4, Bio12, Bio15 NOTE: This is a legacy script that will not work when RGDAL is deprecated in fall 2023.
library(raster)
library(dismo)
library(readr)
library(BioCalc)
workingDirectory <- "USER_WORKING_DIRECTORY/data/inputs/"
setwd(paste0(workingDirectory, "PaleoClimateRaw/"))
# Read in data and process to rasters ----
precipFiles <- list.files(pattern = "precip")
@hannahlowens
hannahlowens / JMIH2019installScript.R
Created July 19, 2019 07:57
Installation script for JMIH R Comp Phy Workshop 2019
install.packages(c('ape', 'geiger', 'phytools', 'RColorBrewer', 'plotrix', 'diversitree', 'OUwie', 'fishtree', 'picante', 'caper'))
@hannahlowens
hannahlowens / PostProcessingModels.R
Last active August 4, 2023 13:15
NOTE: This is a legacy script that will not work when RGDAL is deprecated in fall 2023.
#Post-processing complementary script
#========================================================
#author: Hannah Owens
#date: 13 March, 2018
#Set the working directory
#====================================
setwd("~/Dropbox/ENMSeminar/Labs:Homeworks/Lab9/Data/"); #Change to YOUR working directory
library(raster);
@hannahlowens
hannahlowens / ProcessingEnvironmentalLayers.R
Last active August 4, 2023 13:15
Clipping to mask, saving as an ascii file, and determining Pearson correlation values for pairs of data layers. NOTE: This is a legacy script that will not work when RGDAL is deprecated in fall 2023.
library(raster); #For raster-based loading, calculations, and mapping
library(rgdal); #For reading the M polygon
setwd("~/Dropbox/ENMSeminar/Labs:Homeworks/Lab5/Lab5Data/WorldClimTerrestrial/");
#Navigate to folder containing environmental data
#Loading a raster stack
envtList <- list.files(pattern = ".asc"); #Gets a list of .asc files
envtStack <- stack(envtList); #Reads in .asc files as a raster stack
crs(envtStack) <- "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0" #Defines projection of layers
@hannahlowens
hannahlowens / CleaningPoints.R
Last active August 4, 2023 13:14
Cleaning Occurrence Data. NOTE: This is a legacy script that will not work when RGDAL is deprecated in fall 2023.
library(spocc); #For getting georefernces
library(raster); #For loading and manipulating rasters
library(scrubr); #Package introduced for data cleaning
library(spatstat); #Spatial statistics package with method for calculating nearest neighbor distance
setwd("~/Dropbox/ENMSeminar/Labs:Homeworks/Lab4/"); #Tell R where things go.
#Get your data using SPOCC
spoccCod <- occ(query = "Gadus morhua", from = c('gbif', 'bison', 'inat', 'ecoengine', 'vertnet', 'idigbio', 'obis'), has_coords = T, limit = 100000000);
#Make sure you customize this to take advantage of all of the appropriate databases for your localities.
@hannahlowens
hannahlowens / OccData.R
Created April 12, 2018 09:28
Searching for Occurrence Data
library(rgbif);
library(spocc);
setwd("~/Dropbox/ENMSeminar/Labs:Homeworks/Lab3/"); #Tell R where to put things.
#RGBIF
#This package works specifically for querying the GBIF database.
rGBIFSquirrels <- occ_search(scientificName = "Sciurus niger shermani", hasCoordinate = T);
#Searches all GBIF records for squirrels, only returns occurrences with coordinates
head(rGBIFSquirrels$data);
@hannahlowens
hannahlowens / GIS in R
Last active August 4, 2023 13:14
This script has examples for some useful GIS functions in R. Note that it will not run out of the box: you must change the file locations to reflect where the data you want to use are located. NOTE: This is a legacy script that will not work when RGDAL is deprecated in fall 2023.
#This is the R script for Lab 2 part 1. We will walk you through
#how to do some very basic geospatial operations in R.
#Load the libraries you'll need.
library(raster);
library(maptools);
library(rgdal);
#Set the working directory to the location of the data you
#downloaded for Lab 2. This tells R where to read and write
@hannahlowens
hannahlowens / PackagesForNicheModeling.R
Last active April 14, 2024 09:00
Installs commonly-used packages for ecological niche modeling.
# For niche modeling
# ===================================================
# For loading, calculations, and mapping of spatial data
install.packages("terra")
# For data cleaning
install.packages("dplyr")
# For calculating nearest-neighbor distance
install.packages("spatstat")
#For comparative phylogenetics
#===================================================
install.packages('ctv');
library('ctv');
install.views('Phylogenetics');
update.views('Phylogenetics');
#For niche modeling
#===================================================
#For raster-based loading, calculations, and mapping