This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lubridate) | |
wtr_yr <- function(dates, start_month = 9) { | |
# Convert dates into POSIXlt | |
dates.posix <- as.POSIXlt(dates) | |
# Year offset | |
offset <- ifelse(dates.posix$mon >= start_month - 1, 1, 0) | |
# Water year | |
adj.year <- dates.posix$year + 1900 + offset | |
# Return the water year |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(grid) | |
# define consistent ggplot theme to apply to all figures | |
theme_ms <- function(base_size=12, base_family="Helvetica") { | |
library(grid) | |
(theme_bw(base_size = base_size, base_family = base_family)+ | |
theme(text=element_text(color="black"), | |
axis.title=element_text(face="bold", size = rel(1.3)), | |
axis.text=element_text(size = rel(1), color = "black"), | |
legend.title=element_text(face="bold"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################# | |
## Format p-values for use in Rmarkdown documents | |
## This function modifies base::format.pval() to automate | |
## the inclusion of equalities and inequalities | |
## Author: W.K. Petry | |
################################################# | |
# Arguments: | |
# pv a numeric vector | |
# digits how many significant digits to use; recommended value is 3 | |
# eps numerical tolerance; effectively the smallest p-value to report; recommended value is 10^(-digits) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dplyr pipe ligature ideas: | |
## %>% forward-pipe operator | |
˙>. | |
## %T>% tee operator | |
˙T>. | |
## %<>% compound assignment pipe-operator | |
˙◇. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################# | |
## Illuminating the dark corners of demography | |
## W.K. Petry | |
## | |
## README: This code reproduces the analyses shown on the COM(P)ADRE blog. The analyses were run | |
## at a spatial resolution of 1/12° (>9.3 million cells to cover the Earth!), and will take several hours | |
## to run the necessary calculations on a standard desktop/laptop. It's recommended that the code be run | |
## at a coarser spatial resolution first, increasing the resolution only when accuracy is needed. See the | |
## 'res' parameter under the 'Preliminaries' heading. | |
################################################# |
NewerOlder