/SWMPrExtension

Functions for Analyzing and Plotting SWMP Estuary Monitoring Data from the NERR System archive at

Primary LanguageROtherNOASSERTION

CRAN_Status_BadgeDownloads from the RStudio CRAN mirror

Overview

The System Wide Monitoring Program (SWMP) was implemented by the National Estuarine Research Reserve System (NERRS) in 1995 to provide continuous monitoring data at over 140 continuous monitoring stations in 28 estuaries across the United States. SWMPrExtension (pronounced “swamper extension”) is an R package that provides additional functions to organize and analyze SWMP data and is intended as a companion package for SWMPr (pronounced “swamper”). Currently, there is no citation for SWMPrExtension.

SWMPr is an R package for retrieving, organizing, and analyzing estuary monitoring data from SWMP. SWMPr can be cited as follows:

Beck MW. 2016. SWMPr: An R package for retrieving, organizing, and analyzing environmental data for estuaries. The R Journal. 8(1):219-232. https://journal.r-project.org/archive/2016-1/beck.pdf

NOAA Open Source Disclaimer

This repository is a scientific product and is not official communication of the National Oceanic and Atmospheric Administration, or the United States Department of Commerce. All NOAA GitHub project code is provided on an ?as is? basis and the user assumes responsibility for its use. Any claims against the Department of Commerce or Department of Commerce bureaus stemming from the use of this GitHub project will be governed by all applicable Federal law. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by the Department of Commerce. The Department of Commerce seal and logo, or the seal and logo of a DOC bureau, shall not be used in any manner to imply endorsement of any commercial product or activity by DOC or the United States Government.

Installing the package

Install the package from CRAN:

install.packages('SWMPrExtension')
library(SWMPrExtension)

Install the development (unstable) version from Github:

install.packages('devtools')
library(devtools)
install_github('NOAA-OCM/SWMPrExtension')
library(SWMPrExtension)

Using the package

Documentation for SWMPrExtension is currently in development.

A quick summary of the SWMPr package can be found here. A detailed manuscript describing full use of the SWMPr package is available from the R Journal. All source materials for the manuscript are available here.

SWMPrExtension adds several functions to existing concepts in SWMPr and introduces a new concept called “Reporting”.

Analyze

The core analyses available within the SWMPrExtension R package and used to create the reserve level annual report fall into four general categories: boxplots and barplots, range plots, threshold plots, and trend plots. There is also an additional category called “mapping” which contains functions that generate many of maps associated with the reserve-level reports. The analyses, methods, and maps in this section were selected by and approved by a technical advisory committee composed of NERR research coordinators, SWMP technicians and CDMO staff.

Core Analyses

annual_range.swmpr

For a user-specified year, calculate averages, average ranges, and min/max observed ranges the on a monthly or seasonal basis.

historical_daily_range.swmpr

Compare a user-specified year against historical data on a daily basis.

historical_range.swmpr

Compare a user-specified year against historical data on a monthly/seasonal basis.

raw_boxplot.swmpr

Generate a monthly/seasonal boxplots of raw data for a target year.

seasonal_barplot.swmpr

Generate monthly/seasonal barplot for parameters that are better viewed in on a cumulative basis (e.g. precipitation).

seasonal_boxplot.swmpr

Generate monthly/seasonal boxplots for daily average statistics (min/average/max) across a user-specified time period.Includes the option to calculate a median value for a target year and include a line for a water quality threshold.

seasonal_dot.swmpr

Plot average/min/max seasonal values faceted by season.

sk_seasonal.swmpr

Seasonal Kendall non-parametric test for monotonic seasonal trends.

threshold_criteria_plot.swmpr

Compare raw data against user-specified water quality thresholds

threshold_identification.swmpr

Identify dates and times that a user-specified water quality threshold is exceeded. For continuous monitoring data, the user can also specify the length of time the threshold must be exceeded for the event to be included (e.g. DO must be < 2 mg/L for at least 2 hours).

threshold_percentile_plot.swmpr

Compare raw data against user-specified percentiles calculated from historical data. User has the option to calculate percentiles on a monthly basis.

threshold_summary.swmpr

Summarize the results from threshold_identification in either a plot or tabular format. Results can be aggregated on a monthly, seasonal, or annual basis.

Mapping

national_sk_map

Create a base map for NERRS reserves in ggplot with seasonal kendall results.

res_custom_map

Create a stylized reserve-level map of custom station locations for use with the reserve level reporting template.

res_custom_sk_map

Create a stylized reserve-level map of seasonal kendall results from custom station locations for use with the reserve level reporting template.

res_local_map

Create a stylized reserve-level map for use with the reserve level reporting template.

res_national_map

Create a base map for NERRS reserves in ggplot.

res_sk_map

Create a stylized reserve-level map of seasonal kendall results for use with the reserve level reporting template.

Retrieve

in the SWMPr package, retrieve functions help the user load SWMP data into R.

import_local_nut

A modified version of import_local from the SWMPr package. This version allows the user to specify the collection method (CollMethd) argument to separate monthly nutrient sampling data from monthly 24-hr nutrient sampling data.

Reporting

The new concept of reporting refers to functions that were specifically developed for use with NERRS reserve-level & national-level reporting scripts that are used to generate the reserve-level and national-level annual reports. They are included as part of this package in case users find them useful for their own purposes.

Reserve Level Template

create_sk_flextable_list

Create a list of flextable objects to display Seasonal Kendall results in the NERRS reserve level template.

geographic_unique_stations

Creates an alphabetically sorted, vector of geographically unique stations for mapping. Intended for use with res_local_map.

get_reserve

Return the full name of the reserve associated with the data files in the ‘data’ folder of the reserve level template.

get_shp_name

Return the name of the shape file associated with the data files in the ‘data’ folder of the reserve level template.

get_site_code

Return the 3 letter reserve code associated with the reserve.

get_site_coordinates

Return the station coordinates for stations associated with the data files in the ‘data’ folder of the reserve level template.

get_sites

Return the stations associated with the data files in ‘data’ folder of the reserve level template.

load_shp_file

Load and format shapefile for use with res_local_map.

National Level Template

create_sk_national_ft_reserves

Create a flextable of reserve names for use with the NERRS national level template.

create_sk_national_ft_results

Create a flextable object to display Seasonal Kendall results for each reserve in the NERRS national level template.

summarise_handoff_files

Summarise the seasonal kendall results from reserve level report hand-off files.

Miscellaneous

Miscellaneous functions are generally helper functions that are called internally by other analysis functions.

Analyze

assign_season

Assign seasons to SWMPr sampling data on a monthly basis or user-defined basis. Used by multiple analysis functions to group sampling data into user-defined seasons.

lm_p_labs

Generate a dataframe of p-value labels based on p-values from linear regression. Used internally by seasonal_dot.swmpr to add linear regression results to the plot.

set_date_break_labs

Select reasonable labels for breaks used in scale_x_datetime. Used internally by several analysis functions.

set_date_breaks

A helper function to select reasonable breaks for scale_x_datetime. Used internally by several analysis functions.

sk_tidy

Tidy results from EnvStats::kendallSeasonalTrendTest. Used by sk_seasonal.swmpr to tidy seasonal kendall test results.

std_param_check

Determine if a parameter is one of the standard SWMP parameters.

title_labeler

Generate a plot title based on SWMP station abbreviation. Used internally by several analysis functions.

y_count_labeler

Generate a y-axis label based on SWMP parameter abbreviation. Used internally by several analysis functions.

y_labeler

Generate a y-axis label based on SWMP parameter abbreviation and threshold criteria. Used internally by several analysis functions.

Mapping

reserve_locs

Create a dataframe of selected NERRS locations for plotting with res_national_map.

Reporting

ft_col_names

Convert SWMPr parameter abbreviations into formats appropriate for use with NERRS reserve level template flextable. Used internally by create_sk_flextable_list.

generate_results_table

Filters a data.frame of user-specified results for display in the NERRS reserve level report. Used internally by create_sk_flextable_list.

generate_station_table

Filters a data.frame of user-specified results for display in the NERRS reserve level report. Used internally by create_sk_flextable_list.

remove_inf_and_nan

Removes -Inf, Inf, and NaN from a matrix. Used internally by several functions to prevent plotting errors.

Datasets

The following data sets are included within the SWMPrExtension package. They are used for examples and for mapping.

cbm_spatial

A shapefile of the reserve boundary for Chesapeake Bay-Maryland NERR. Available from: https://cdmo.baruch.sc.edu/.

elk_spatial

A shapefile of the reserve boundary for Elkhorn Slough NERR. Available from: https://cdmo.baruch.sc.edu/.

elknmnut

Nutrient data (2007-2016) from North Marsh station at Elkhorn Slough NERR.

elksmwq

Water quality data (2007-2016) from South Marsh station at Elkhorn Slough NERR.

sampling_stations

Metadata on NERRS stations provided by the Central Data Management Office (CDMO) when data is downloaded. Additional formatting applied in order to make the dataset useful to several SWMPrExtension functions.

us_laea

US County boundaries from the US Census Bureau’s MAF/TIGER geographic database, modified to remove non-ASCII characters. Reprojected using Lambert Azimuthal Equal Area. Used to create national-level maps.