A comprehensive framework for analyzing agricultural nutrient
balances across multiple spatial scales (county, 'HUC8', 'HUC2') with
integration of wastewater treatment plant ('WWTP') effluent loads for both
nitrogen and phosphorus. Supports classification of spatial units as
nutrient sources, sinks, or balanced areas based on agricultural surplus
and deficit calculations. Includes visualization tools, spatial transition
probability analysis, and nutrient flow network mapping. Built-in datasets
include agricultural nutrient balance data from the Nutrient Use Geographic
Information System ('NuGIS'; The Fertilizer Institute and Plant Nutrition
Canada, 1987-2016) < https://nugis.tfi.org/tabular_data/> and U.S. Environmental
Protection Agency ('EPA') wastewater discharge data from the 'ECHO' Discharge
Monitoring Report ('DMR') Loading Tool (2007-2016)
< https://echo.epa.gov/trends/loading-tool/water-pollution-search>. Data
are downloaded on demand from the Open Science Framework ('OSF') repository to
minimize package size while maintaining full functionality. The integrated
'manureshed' framework methodology is described in Akanbi et al. (2025)
Spatiotemporal Nutrient Balance Analysis Across Agricultural and Municipal Systems
An R package for analyzing integrated agricultural-municipal nutrient flows and watershed management. The manureshed framework enables comprehensive analysis of nitrogen and phosphorus balances across multiple spatial scales (county, HUC8, HUC2) with seamless integration of wastewater treatment plant (WWTP) discharge data.
quick_analysis() for complete workflowbatch_analysis_years()# Install the stable version from CRAN
install.packages("manureshed")
# Install development version with latest features
# install.packages("devtools")
devtools::install_github("cwru-sdle/manureshed")
# Enhanced visualization and spatial analysis
install.packages(c("ggplot2", "sf", "dplyr", "tidyr", "viridis"))
# Optional packages for advanced features
install.packages(c("tigris", "nhdplusTools", "igraph", "cowplot"))
library(manureshed)
# Check what data is available
check_builtin_data()
# Download all datasets (optional, ~40MB total)
download_all_data()
# Test connection to data repository
test_osf_connection()
# Check package health
health_check()
# 1. Quick analysis with automatic visualizations
results <- quick_analysis(
scale = "county",
year = 2016,
nutrients = "nitrogen",
include_wwtp = TRUE
)
# 2. Comprehensive analysis for both nutrients
results_both <- run_builtin_analysis(
scale = "huc8",
year = 2016,
nutrients = c("nitrogen", "phosphorus"),
include_wwtp = TRUE,
output_dir = "analysis_results"
)
# 3. Historical analysis (2007-2016 WWTP available!)
historical <- run_builtin_analysis(
scale = "county",
year = 2010,
nutrients = "nitrogen",
include_wwtp = TRUE
)
# 4. Multi-year analysis
batch_results <- batch_analysis_years(
scale = "huc8",
years = c(2010, 2012, 2014, 2016),
nutrients = "phosphorus",
include_wwtp = TRUE
)
# 5. State-specific analysis
ohio <- run_state_analysis(
state = "OH",
scale = "county",
year = 2016,
nutrients = c("nitrogen", "phosphorus"),
include_wwtp = TRUE
)
# View all available functions
help(package = "manureshed")
# Key workflow functions
?run_builtin_analysis
?quick_analysis
?batch_analysis_years
?run_state_analysis
# Data loading functions
?load_builtin_nugis
?load_builtin_wwtp
?load_builtin_boundaries
# Custom data integration
?load_user_wwtp
?wwtp_clean_data
# Visualization functions
?map_agricultural_classification
?map_wwtp_points
?map_wwtp_influence
# Utility functions
?check_builtin_data
?citation_info
?health_check
# Analyze nitrogen flows in the Great Lakes region
great_lakes <- run_builtin_analysis(
scale = "huc8",
year = 2016,
nutrients = "nitrogen",
include_wwtp = TRUE,
output_dir = "great_lakes_analysis"
)
# Extract key statistics
summary_stats <- create_classification_summary(
great_lakes$nitrogen$agri_classified,
great_lakes$nitrogen$integrated_result
)
# Visualize impact
plot_before_after_comparison(summary_stats)
# Load watershed boundaries
huc8_boundaries <- load_builtin_boundaries("huc8")
# Analyze nutrient balance
watershed_balance <- run_builtin_analysis(
scale = "huc8",
year = 2016,
nutrients = c("nitrogen", "phosphorus"),
include_wwtp = TRUE
)
# Calculate transition probabilities
transitions_n <- calculate_transition_probabilities(
watershed_balance$nitrogen$agri_classified,
watershed_balance$nitrogen$integrated_result
)
# Visualize network flows
create_network_plot(
transitions_n,
nutrient = "nitrogen",
title = "HUC8 Nitrogen Classification Transitions"
)
# Load your own WWTP data for any year
custom_wwtp <- load_user_wwtp(
file_path = "my_wwtp_2018.csv",
nutrient = "nitrogen",
column_mapping = list(
facility = "Facility_Name",
latitude = "Lat",
longitude = "Long",
load = "Total_N_kg"
),
load_units = "kg"
)
# Integrate with agricultural data
custom_results <- run_builtin_analysis(
scale = "county",
year = 2016, # Use 2016 agricultural data
nutrients = "nitrogen",
include_wwtp = TRUE,
custom_wwtp_nitrogen = custom_wwtp
)
# Analyze trends across multiple years
trend_results <- batch_analysis_years(
scale = "county",
years = seq(2010, 2016, by = 2),
nutrients = c("nitrogen", "phosphorus"),
include_wwtp = TRUE,
output_dir = "trend_analysis"
)
# Available years for WWTP: 2007-2016
list_available_years()
# Quick state analysis with maps
iowa_results <- quick_state_analysis(
state = "IA",
scale = "county",
year = 2016,
nutrients = "nitrogen"
)
# Multiple states
midwest_states <- c("IA", "IL", "IN", "OH", "MI")
midwest_results <- lapply(midwest_states, function(state) {
run_state_analysis(
state = state,
scale = "county",
year = 2016,
nutrients = "nitrogen",
include_wwtp = TRUE
)
})
names(midwest_results) <- midwest_states
The manureshed concept represents a paradigm shift from treating agricultural and municipal nutrient systems separately to analyzing them as integrated socio-environmental systems. This enables:
Designed specifically for reproducible research:
Source: The Fertilizer Institute (TFI) and Plant Nutrition Canada (PNC)
Website: https://nugis.tfi.org/tabular_data
Components:
Spatial Scales: County, HUC8, HUC2
Citation: Use citation_info() for complete attribution
Source: U.S. Environmental Protection Agency
System: Discharge Monitoring Report (DMR) Loading Tool via ECHO
Website: https://echo.epa.gov/trends/loading-tool/water-pollution-search
Parameters:
Pre-processing: Cleaned and quality-controlled in manureshed package
License: Public domain (U.S. Government work)
Sources:
Projection: Albers Equal Area Conic (EPSG:5070)
Coverage: Continental United States (CONUS)
The package is optimized for:
# Check package health
health_check()
# Pre-download all data for offline work
download_all_data()
# Clear cache if needed
clear_data_cache()
# Use quick_check to validate results
quick_check(results)
# For large batch analyses, process in chunks
years_chunk1 <- seq(2007, 2011)
years_chunk2 <- seq(2012, 2016)
# Core dependencies (automatically installed)
sf (>= 1.0-0)
dplyr (>= 1.0.0)
ggplot2 (>= 3.3.0)
tidyr (>= 1.0.0)
jsonlite
rlang
# Install these for full functionality
install.packages(c(
"viridis", # Color schemes
"tigris", # US boundaries
"nhdplusTools", # Watershed tools
"igraph", # Network analysis
"cowplot" # Multi-panel plots
))
If you use manureshed in your research, please cite:
citation("manureshed")
Akanbi, O. D.; Mandayam, V.; Gupta, A.; Flynn, K. C.; Yarus, J. M.; Barcelos, E. I.; & French, R. H. (2025). manureshed: An Open-Source R Package for Scalable Temporal and Multi-Regional Analysis of Integrated Agricultural-Municipal Nutrient Flows. R package version 0.1.0. OSF Repository: https://osf.io/g39xa/
Akanbi, O. D.; Gupta, A.; Mandayam, V.; Flynn, K. C.; Yarus, J. M.; Barcelos, E. I.; French, R. H. Towards Circular Nutrient Economies: An Integrated Manureshed Framework for Agricultural and Municipal Resource Management. Resources, Conservation and Recycling, 2025. https://doi.org/10.1016/j.resconrec.2025.108697
Use citation_info() to display complete citations for:
We welcome contributions! To contribute:
MIT License - see LICENSE file for details.
This material is based upon financial support by the National Science Foundation, EEC Division of Engineering Education and Centers, NSF Engineering Research Center for Advancing Sustainable and Distributed Fertilizer Production (CASFER), NSF 20-553 Gen-4 Engineering Research Centers award 2133576.
sf, terra, ggplot2 developers)Ready to get started? Install from CRAN with install.packages("manureshed") and check out the Getting Started vignette!
Questions? Run health_check() to verify your installation, or use citation_info() for publication citations.