Skip to content

Instantly share code, notes, and snippets.

@sdtaylor
sdtaylor / getNEONdata.R
Created July 8, 2020 16:07
neon data data download eample
library(tidyverse)
library(neonUtilities)
library(geoNEON)
sites = c('JORN','TALL','BART','BARR', 'HARV','YELL')
for(site_id in sites){
woody_structure=tryCatch(neonUtilities::loadByProduct('DP1.10098.001', site=site_id,
startdate = '2018-01', enddate = '2018-12',
@sdtaylor
sdtaylor / rotate-axis-labels-ggplot2.R
Created June 12, 2020 12:21 — forked from benmarwick/rotate-axis-labels-ggplot2.R
I can never remember how to rotate the x-axis labels with ggplot2: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
# Adapted from https://stackoverflow.com/a/7267364/1036500 by Andrie de Vries
# This is it: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
library(ggplot2)
td <- expand.grid(
hjust=c(0, 0.5, 1),
vjust=c(0, 0.5, 1),
angle=c(0, 45, 90),
@sdtaylor
sdtaylor / os_stuff.sh
Created June 1, 2020 12:54
R 4.0 on Ubuntu
# Run these first to get all the relevant packages
# For R 4.0 on ubuntio 18.04
# from https://www.digitalocean.com/community/tutorials/how-to-install-r-on-ubuntu-18-04
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/'
sudo apt-get update
sudo apt-get install r-base
# The following packages are also needed for various things in the tidyverse
@sdtaylor
sdtaylor / all_the_colors.R
Last active September 20, 2019 17:44
Generate discrete color values for numerous categories (>10)
library(ggplot2)
# Make a vector of colors of size n based on an RColorBrewer palette
# or list of colors.
get_extended_palette = function(original_palette = 'Paired', n){
brewer_palettes = rownames(RColorBrewer::brewer.pal.info)
if(length(original_palette)>=2){
original_palette_values = original_palette
} else if(original_palette %in% brewer_palettes){
original_palette_values = RColorBrewer::brewer.pal(9, original_palette) # most of the palettes have 9 colors to start with
@sdtaylor
sdtaylor / usa_grid_map.R
Created March 12, 2019 17:15
Straightforward USA map with lat/lon grid.
library(tidyverse)
basemap = map_data('state')
lat_range = c(20,60)
lon_range = c(-150,50)
ggplot() +
geom_polygon(data = basemap, aes(x=long, y = lat, group = group), fill=NA, color='black', size=1.5) +
scale_x_continuous(breaks=seq(lon_range[1],lon_range[2],10), minor_breaks = seq(lon_range[1],lon_range[2],1)) +
@sdtaylor
sdtaylor / .bashrc
Last active December 30, 2020 00:02
bashrc stuff
alias aptupdate='sudo apt-get update'
alias aptupgrade='sudo apt-get upgrade'
alias aptinstall='sudo apt-get install'
alias aptremove='sudo apt-get remove'
function csvhead {
head "$@" | sed 's/,,/, ,/g;s/,,/, ,/g' | column -t -s,
}
@sdtaylor
sdtaylor / delete_extra_bib_stuff.R
Last active April 26, 2021 21:05
Delete unneeded bib items
library(bib2df)
x = bib2df('manuscript/sample.bib')
x$ANNOTE=NA
x$MENDELEY.GROUPS=NA
x$MENDELEY.TAGS=NA
x$ABSTRACT=NA
x$FILE=NA
x$KEYWORDS=NA
@sdtaylor
sdtaylor / weecology_trees.geojson
Last active April 29, 2019 19:31
Trees of Weecology
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sdtaylor
sdtaylor / florida_winter_freezing_days.R
Last active December 2, 2020 14:33
North Florida Winter's
library(tidyverse)
library(cowplot)
#########################
# Get data
zipped_files = c("1997_daily.csv.zip", "1998_daily.csv.zip", "1999_daily.csv.zip", "2000_daily.csv.zip", "2001_daily.csv.zip", "2002_daily.csv.zip",
"2003_daily.csv.zip", "2004_daily.csv.zip", "2005_daily.csv.zip", "2006_daily.csv.zip", "2007_daily.csv.zip", "2008_daily.csv.zip",
"2009_daily.csv.zip", "2010_daily.csv.zip", "2011_daily.csv.zip", "2012_daily.csv.zip", "2013_daily.zip", "2014_daily.zip",
"2015_daily.zip", "2016_daily.zip", "2017_daily.zip", "2018_daily.zip","2019_daily.zip","2020_daily.zip")
data_folder = 'fawn_data/'
@sdtaylor
sdtaylor / get_forecast.R
Last active February 27, 2018 16:20
download climate locations for a single location
library(lubridate)
library(dplyr)
####################################################################################
#' Download downscaled climate forecast data
#'
#' Individual climate models available are are c('CFSv2','CMC1','CMC2','GFDL-FLOR','GFDL','NASA','NCAR'),
#' 'ENSMEAN' is the mean of all models.
#' lead_time is the months into the future to obtain forecasts. Max of 7
#' Default lat and lon are for Portal, AZ