diff --git a/DESCRIPTION b/DESCRIPTION index d8610ed..1c9ada2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -42,4 +42,4 @@ Suggests: testthat Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/NAMESPACE b/NAMESPACE index 9a85667..66e9728 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,14 +3,17 @@ export("%>%") export(check_default_data_path) export(check_for_newer_data) +export(coastal_analysis) export(coastal_indicator) export(download_observations) export(dry_down) +export(foraging_analysis) export(foraging_indicator) export(format_code) export(format_todo) export(format_value) export(get_default_data_path) +export(initiation_analysis) export(initiation_indicator) export(load_datafile) export(load_indicator_data) @@ -21,6 +24,7 @@ export(plot_coastal) export(plot_foraging) export(plot_initiation) export(plot_supercolony) +export(supercolony_analysis) export(supercolony_indicator) export(use_default_data_path) export(water_report) diff --git a/R/indicator_analysis.R b/R/indicator_analysis.R new file mode 100644 index 0000000..4a9bfea --- /dev/null +++ b/R/indicator_analysis.R @@ -0,0 +1,183 @@ +#' @name foraging_analysis +#' +#' @title Produce status figures of tactile/visual foraging indicator data +#' +#' @description Analyze a table of rolling averages for the proportion of tactile/visual foragers, +#' by year, and plot with thresholds by year +#' +#' @param minyear Earliest year to include +#' @param maxyear Most recent year to include +#' @param window number of years over which to create a rolling average +#' +#' @inheritParams load_indicator_data +#' +#' @return a data.frame +#' +#' @export +#' +foraging_analysis <- function(path = get_default_data_path(), + minyear = 1986, maxyear = as.integer(format(Sys.Date(), "%Y")), + window = 3, + download_if_missing = TRUE) +{ + library(ggplot2) + foraging <- foraging_indicator(minyear = 2004) %>% + dplyr::mutate(period="historic") %>% + dplyr::mutate(period = replace(period, year > 2016, "modern")) + + A <- ggplot(foraging, aes(x=proportion_mean, fill=period)) + + geom_density(adjust = 1, alpha=0.5) + + xlim(0,10) + + labs(title="Average Foraging Ratio", x="tactile/visual", y = "density") + + theme_classic() + + theme(legend.position = c(.85,.9)) + + B <- ggplot(foraging, aes(x=year, y=proportion_mean, + ymin=proportion_mean-proportion_sd, ymax=proportion_mean+proportion_sd)) + + geom_line(color="black", show.legend = FALSE) + + geom_ribbon(alpha=0.2, fill="grey", show.legend = FALSE) + + geom_ribbon(alpha=0.5, aes(color=NULL, fill=period), show.legend = FALSE) + + labs(x="Year", y = "tactile/visual") + + theme_classic() + + cowplot::plot_grid(A, B, labels = NULL) +} + +#' @name initiation_analysis +#' +#' @title Produce status figures of wood stork nesting intiation indicator data +#' +#' @description Analyze a table of rolling averages for the date of wood stork nest initiation, +#' by year +#' +#' @param minyear Earliest year to include +#' @param maxyear Most recent year to include +#' @param window number of years over which to create a rolling average +#' +#' @inheritParams load_indicator_data +#' +#' @return a data.frame +#' +#' @export +#' +initiation_analysis <- function(path = get_default_data_path(), + minyear = 1986, maxyear = as.integer(format(Sys.Date(), "%Y")), + window = 3, + download_if_missing = TRUE) +{ +library(ggplot2) +initiation <- initiation_indicator(minyear = 2004) %>% + dplyr::mutate(period="historic") %>% + dplyr::mutate(period = replace(period, year > 2016, "modern")) + + A <- ggplot(initiation, aes(x=date_score_mean, fill=period)) + + geom_density(adjust = 1, alpha=0.5) + + scale_x_reverse(limits=c(5,-.2), breaks=c(4,3,2,1,0),labels=c("December","January","February","March","April")) + + labs(title="Average Stork Nest Initiation Date", x="Date Score", y = "density") + + theme_classic() + + theme(legend.position=c(.9,.8)) + + B <- ggplot(initiation, aes(x=year, y=date_score_mean, + ymin=date_score_mean-date_score_sd, ymax=date_score_mean+date_score_sd)) + + geom_line(color="black") + + geom_ribbon(alpha=0.2, fill="grey") + + geom_ribbon(alpha=0.5, aes(color=NULL, fill=period)) + + scale_y_reverse(limits=c(4.55,0), breaks=c(4,3,2,1,0),labels=c("December","January","February","March","April")) + + labs(x="Year", y = "Date Score") + + theme_classic() + + theme(legend.position="none") + + cowplot::plot_grid(A, B, labels = NULL) +} + +#' @name coastal_analysis +#' +#' @title Produce status figures of wood stork nesting intiation indicator data +#' +#' @description Analyze a table of rolling averages for the proportion of coastal nesters, +#' by year, and plot with thresholds +#' +#' @param minyear Earliest year to include +#' @param maxyear Most recent year to include +#' @param window number of years over which to create a rolling average +#' +#' @inheritParams load_indicator_data +#' +#' @return a data.frame +#' +#' @export +#' +coastal_analysis <- function(path = get_default_data_path(), + minyear = 1986, maxyear = as.integer(format(Sys.Date(), "%Y")), + window = 3, + download_if_missing = TRUE) +{ +library(ggplot2) + coastal <- coastal_indicator(minyear = 2004) %>% + dplyr::mutate(period="historic") %>% + dplyr::mutate(period = replace(period, year > 2016, "modern")) + + A <- ggplot(coastal, aes(x=proportion_mean, fill=period)) + + geom_density(adjust = 1.5, alpha=0.5) + + xlim(0,.5) + + labs(title="Average proportion nests in coastal colonies", x="proportion coastal", y = "density") + + theme_classic() + + theme(legend.position=c(.9,.8)) + + B <- ggplot(coastal, aes(x=year, y=proportion_mean, + ymin=proportion_mean-proportion_sd, ymax=proportion_mean+proportion_sd)) + + geom_line(color="black") + + geom_ribbon(alpha=0.2, fill="grey") + + geom_ribbon(alpha=0.5, aes(color=NULL, fill=period)) + + labs(x="Year", y = "proportion coastal") + + theme_classic() + + theme(legend.position="none") + + cowplot::plot_grid(A, B, labels = NULL) +} + +#' @name supercolony_analysis +#' +#' @title Produce status figures of ibis supercolony indicator data +#' +#' @description Analyze a table of rolling averages for the interval between ibis supercolony +#' events, by year +#' +#' @param minyear Earliest year to include +#' @param maxyear Most recent year to include +#' @param window number of years over which to create a rolling average +#' +#' @inheritParams load_indicator_data +#' +#' @return a data.frame +#' +#' @export +#' +supercolony_analysis <- function(path = get_default_data_path(), + minyear = 1986, maxyear = as.integer(format(Sys.Date(), "%Y")), + window = 3, + download_if_missing = TRUE) +{ +library(ggplot2) + supercolony <- supercolony_indicator(minyear = 2004) %>% + dplyr::mutate(period="historic") %>% + dplyr::mutate(period = replace(period, year > 2016, "modern")) + + A <- ggplot(supercolony, aes(x=interval_mean, fill=period)) + + geom_density(adjust = 1, alpha=0.5) + + xlim(0,3) + + labs(title="Ibis supercolony mean interval", x="mean interval", y = "density") + + theme_classic() + + theme(legend.position=c(.9,.8)) + + B <- ggplot(supercolony, aes(x=year, y=interval_mean, + ymin=interval_mean-interval_sd, ymax=interval_mean+interval_sd)) + + geom_line(color="black") + + geom_ribbon(alpha=0.2, fill="grey") + + geom_ribbon(alpha=0.5, aes(color=NULL, fill=period)) + + labs(x="Year", y = "mean interval") + + theme_classic() + + theme(legend.position="none") + + cowplot::plot_grid(A, B, labels = NULL) +} diff --git a/R/report_work.R b/R/report_work.R index 01cecdf..e84b682 100644 --- a/R/report_work.R +++ b/R/report_work.R @@ -66,6 +66,9 @@ initiation_indicator <- function(path = get_default_data_path(), dplyr::filter(dplyr::between(.data$year, minyear, maxyear)) %>% dplyr::arrange(.data$year) %>% dplyr::mutate(date_score_mean = zoo::rollapply(.data$date_score, FUN="mean", + width=window, align="right", + partial = TRUE), + date_score_sd = zoo::rollapply(.data$date_score, FUN="sd", width=window, align="right", partial = TRUE)) } @@ -98,6 +101,9 @@ coastal_indicator <- function(path = get_default_data_path(), dplyr::filter(dplyr::between(.data$year, minyear, maxyear)) %>% dplyr::arrange(.data$year) %>% dplyr::mutate(proportion_mean = zoo::rollapply(.data$proportion, FUN="mean", + width=window, align="right", + partial = TRUE), + proportion_sd = zoo::rollapply(.data$proportion, FUN="sd", width=window, align="right", partial = TRUE)) } @@ -136,6 +142,9 @@ foraging_indicator <- function(path = get_default_data_path(), dplyr::ungroup() %>% dplyr::arrange(.data$year) %>% dplyr::mutate(proportion_mean = zoo::rollapply(.data$proportion, FUN="mean", + width=window, align="right", + partial = TRUE), + proportion_sd = zoo::rollapply(.data$proportion, FUN="sd", width=window, align="right", partial = TRUE)) } @@ -168,7 +177,10 @@ supercolony_indicator <- function(path = get_default_data_path(), dplyr::filter(dplyr::between(.data$year, minyear, maxyear)) %>% dplyr::mutate(interval_mean = zoo::rollapply(.data$ibis_interval, FUN="mean", width=window, align="right", - partial = TRUE)) + partial = TRUE), + interval_sd = zoo::rollapply(.data$ibis_interval, FUN="sd", + width=window, align="right", + partial = TRUE)) } #' @name plot_foraging diff --git a/R/wader-package.R b/R/wader-package.R index 0ad58c0..57f2d66 100644 --- a/R/wader-package.R +++ b/R/wader-package.R @@ -5,7 +5,6 @@ #' It contains a set of functions to download, clean, and summarize the data. #' #' @name wader -#' @docType package #' @keywords package #' #' @importFrom lubridate "%m+%" @@ -14,8 +13,7 @@ #' @importFrom stats median na.omit sd setNames time #' @importFrom httr content GET stop_for_status #' - -NULL +"_PACKAGE" ## quiets concerns of R CMD check re: variables used in NSE functions if (getRversion() >= "2.15.1") utils::globalVariables( diff --git a/man/coastal_analysis.Rd b/man/coastal_analysis.Rd new file mode 100644 index 0000000..612a3d6 --- /dev/null +++ b/man/coastal_analysis.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/indicator_analysis.R +\name{coastal_analysis} +\alias{coastal_analysis} +\title{Produce status figures of wood stork nesting intiation indicator data} +\usage{ +coastal_analysis( + path = get_default_data_path(), + minyear = 1986, + maxyear = as.integer(format(Sys.Date(), "\%Y")), + window = 3, + download_if_missing = TRUE +) +} +\arguments{ +\item{path}{either the file path that contains the Wading Bird folder or +"repo", which then pulls data from the EvergladesWadingBird GitHub repository} + +\item{minyear}{Earliest year to include} + +\item{maxyear}{Most recent year to include} + +\item{window}{number of years over which to create a rolling average} + +\item{download_if_missing}{if the specified file path doesn't have the +EvergladesWadingBird folder, then download it} +} +\value{ +a data.frame +} +\description{ +Analyze a table of rolling averages for the proportion of coastal nesters, +by year, and plot with thresholds +} diff --git a/man/foraging_analysis.Rd b/man/foraging_analysis.Rd new file mode 100644 index 0000000..a0eab61 --- /dev/null +++ b/man/foraging_analysis.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/indicator_analysis.R +\name{foraging_analysis} +\alias{foraging_analysis} +\title{Produce status figures of tactile/visual foraging indicator data} +\usage{ +foraging_analysis( + path = get_default_data_path(), + minyear = 1986, + maxyear = as.integer(format(Sys.Date(), "\%Y")), + window = 3, + download_if_missing = TRUE +) +} +\arguments{ +\item{path}{either the file path that contains the Wading Bird folder or +"repo", which then pulls data from the EvergladesWadingBird GitHub repository} + +\item{minyear}{Earliest year to include} + +\item{maxyear}{Most recent year to include} + +\item{window}{number of years over which to create a rolling average} + +\item{download_if_missing}{if the specified file path doesn't have the +EvergladesWadingBird folder, then download it} +} +\value{ +a data.frame +} +\description{ +Analyze a table of rolling averages for the proportion of tactile/visual foragers, +by year, and plot with thresholds by year +} diff --git a/man/initiation_analysis.Rd b/man/initiation_analysis.Rd new file mode 100644 index 0000000..418a196 --- /dev/null +++ b/man/initiation_analysis.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/indicator_analysis.R +\name{initiation_analysis} +\alias{initiation_analysis} +\title{Produce status figures of wood stork nesting intiation indicator data} +\usage{ +initiation_analysis( + path = get_default_data_path(), + minyear = 1986, + maxyear = as.integer(format(Sys.Date(), "\%Y")), + window = 3, + download_if_missing = TRUE +) +} +\arguments{ +\item{path}{either the file path that contains the Wading Bird folder or +"repo", which then pulls data from the EvergladesWadingBird GitHub repository} + +\item{minyear}{Earliest year to include} + +\item{maxyear}{Most recent year to include} + +\item{window}{number of years over which to create a rolling average} + +\item{download_if_missing}{if the specified file path doesn't have the +EvergladesWadingBird folder, then download it} +} +\value{ +a data.frame +} +\description{ +Analyze a table of rolling averages for the date of wood stork nest initiation, +by year +} diff --git a/man/supercolony_analysis.Rd b/man/supercolony_analysis.Rd new file mode 100644 index 0000000..73cdce8 --- /dev/null +++ b/man/supercolony_analysis.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/indicator_analysis.R +\name{supercolony_analysis} +\alias{supercolony_analysis} +\title{Produce status figures of ibis supercolony indicator data} +\usage{ +supercolony_analysis( + path = get_default_data_path(), + minyear = 1986, + maxyear = as.integer(format(Sys.Date(), "\%Y")), + window = 3, + download_if_missing = TRUE +) +} +\arguments{ +\item{path}{either the file path that contains the Wading Bird folder or +"repo", which then pulls data from the EvergladesWadingBird GitHub repository} + +\item{minyear}{Earliest year to include} + +\item{maxyear}{Most recent year to include} + +\item{window}{number of years over which to create a rolling average} + +\item{download_if_missing}{if the specified file path doesn't have the +EvergladesWadingBird folder, then download it} +} +\value{ +a data.frame +} +\description{ +Analyze a table of rolling averages for the interval between ibis supercolony +events, by year +} diff --git a/man/wader.Rd b/man/wader.Rd index 92cae7c..78289db 100644 --- a/man/wader.Rd +++ b/man/wader.Rd @@ -2,11 +2,21 @@ % Please edit documentation in R/wader-package.R \docType{package} \name{wader} +\alias{wader-package} \alias{wader} \title{Creates summaries of the EvergladesWadingBird data} \description{ This package is designed to be an interface to the Wading Bird data, which resides online at \url{https://github.com/weecology/EvergladesWadingBird}. It contains a set of functions to download, clean, and summarize the data. +} +\author{ +\strong{Maintainer}: Glenda M. Yenni \email{glenda@weecology.org} (\href{https://orcid.org/0000-0001-6969-1848}{ORCID}) + +Authors: +\itemize{ + \item Ethan P. White \email{ethan@weecology.org} (\href{https://orcid.org/0000-0001-6728-7745}{ORCID}) +} + } \keyword{package}