Skip to contents

This package provides comprehensive tools for analyzing agricultural nutrient balances at multiple spatial scales with optional integration of wastewater treatment plant (WWTP) nutrient loads for both nitrogen and phosphorus.

Details

All datasets are downloaded on-demand from OSF repository to minimize package size while maintaining full functionality.

Main Functions

Data Loading and Management:

High-Level Workflows:

Agricultural Classification:

WWTP Processing:

Data Integration:

Visualization and Mapping:

Spatial Analysis:

Comparison Analysis:

Utility Functions:

Spatial Scales

The package supports analysis at three spatial scales:

  • County: US county boundaries (3,000+ units)

  • HUC8: 8-digit Hydrologic Unit Code watersheds (2,000+ units)

  • HUC2: 2-digit Hydrologic Unit Code regions (18 units)

Nutrients Supported

The package supports analysis for both major nutrients with appropriate methodologies:

  • Nitrogen: Uses 0.5 availability factor for manure nitrogen in calculations

  • Phosphorus: Direct calculation without availability factor

Users can analyze one nutrient, both nutrients, or different combinations in the same workflow: nutrients = c("nitrogen", "phosphorus")

Classification System

Spatial units are classified into five categories based on nutrient balance:

  • Source: Net nutrient surplus available for export

  • Sink Deficit: Total deficit requiring nutrient imports

  • Sink Fertilizer: Fertilizer surplus available for manure import

  • Within Watershed/County: Balanced for internal nutrient transfers

  • Excluded: Insufficient cropland for meaningful analysis (<500 ha equivalent)

Data Sources

The package provides access to comprehensive built-in datasets:

NuGIS Data:

  • County-level data (1987 - 2016)

  • HUC8 watershed data (1987 - 2016)

  • HUC2 regional data (1987 - 2016)

  • All nutrient balance components (manure, fertilizer, removal, fixation)

Spatial Boundaries:

  • US county boundaries (CONUS)

  • HUC8 watershed boundaries

  • HUC2 regional boundaries

  • All in Albers Equal Area Conic projection (EPSG:5070)

WWTP Data:

  • Nitrogen discharge data (2007 - 2016)

  • Phosphorus discharge data (2007 - 2016)

  • Pre-processed and classification-ready

  • Includes facility metadata and spatial coordinates

Supplemental Data:

  • Texas HUC8 data (automatically integrated for HUC8 analyses)

  • Texas spatial boundaries

OSF Data Repository

All datasets are hosted on OSF and downloaded on-demand:

  • Repository: https://osf.io/g39xa/

  • Automatic caching: Data downloaded once and reused

  • Flexible loading: Load only the data you need

  • Version control: Permanent DOI for reproducibility

  • Size efficiency: Package <1MB, full datasets ~25MB

WWTP Data Flexibility

The package handles varying EPA WWTP data formats across different years:

  • Unit Conversion: Automatic conversion between kg, lbs, pounds, and tons

  • Column Mapping: Flexible mapping to handle EPA naming changes

  • Header Detection: Support for different header row positions

  • Built-in 2016: Ready-to-use cleaned data for immediate analysis

  • Custom Integration: Easy integration of user data for other years

Workflow Examples


# Check what data is available
check_builtin_data()

# Download all datasets (optional, ~40MB)
download_all_data()

# Basic analysis using built-in data - any year 2007-2016
results <- run_builtin_analysis(
  scale = "huc8",
  year = 2012,  # Any year 2007-2016 now supported
  nutrients = c("nitrogen", "phosphorus"),
  include_wwtp = TRUE
)

wwtp_n_2010 <- load_builtin_wwtp("nitrogen", year = 2010)
wwtp_p_2015 <- load_builtin_wwtp("phosphorus", year = 2015)


# Quick analysis with automatic visualizations
viz_results <- quick_analysis(
  scale = "county",
  year = 2016,
  nutrients = "nitrogen",
  include_wwtp = TRUE
)

# Historical analysis without WWTP
historical <- run_builtin_analysis(
  scale = "huc8",
  year = 2010,
  nutrients = c("nitrogen", "phosphorus"),
  include_wwtp = FALSE
)

# Load specific datasets manually
county_2016 <- load_builtin_nugis("county", 2016)
boundaries <- load_builtin_boundaries("county")
wwtp_n <- load_builtin_wwtp("nitrogen")

Analysis Outputs

The package generates comprehensive outputs for each nutrient analyzed:

  • Spatial Data: Classification results as sf objects

  • Maps: Classification, influence, and facility maps

  • Networks: Transition probability visualizations

  • Comparisons: Before/after WWTP integration analysis

  • Data Files: CSV centroids, RDS spatial data

  • Metadata: Analysis parameters and processing information

Performance and Scalability

  • Optimized for CONUS-scale analysis (1000s of spatial units)

  • Memory-efficient spatial operations

  • On-demand data loading reduces memory footprint

  • Progress reporting for long-running analyses

  • Automatic garbage collection for memory management

Author

Maintainer: Olatunde D. Akanbi olatunde.akanbi@case.edu (ORCID) [copyright holder]

Authors: