Also make sure you have nhdplusTools installed - I am leveraging some functions from that package to complement grabbing Streamcat data. I’m also using mapview package.
# requires devtools to install
# install.packages('devtools')
library(devtools)
# install from repository
# install_github('USEPA/StreamCatTools')
library(StreamCatTools)
library(sf)
library(nhdplusTools)
library(readr)
library(mapview)
library(dplyr)
library(knitr)
library(readr)
library(purrr)
library(tidyr)
library(ggplot2)
library(jsonlite)
sessionInfo()
## R version 4.0.0 (2020-04-24)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 16299)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United States.1252
## [2] LC_CTYPE=English_United States.1252
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United States.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] jsonlite_1.6.1 ggplot2_3.3.1
## [3] tidyr_1.1.0 purrr_0.3.4
## [5] knitr_1.28 dplyr_1.0.0
## [7] mapview_2.7.8 readr_1.3.1
## [9] nhdplusTools_0.3.13 sf_0.9-3
## [11] StreamCatTools_0.0.0.9000 devtools_2.3.0
## [13] usethis_1.6.1
##
## loaded via a namespace (and not attached):
## [1] httr_1.4.1 pkgload_1.1.0 viridisLite_0.3.0 assertthat_0.2.1
## [5] sp_1.4-2 stats4_4.0.0 yaml_2.2.1 remotes_2.1.1
## [9] sessioninfo_1.1.1 pillar_1.4.4 backports_1.1.7 lattice_0.20-41
## [13] glue_1.4.1 digest_0.6.25 colorspace_1.4-1 htmltools_0.4.0
## [17] pkgconfig_2.0.3 raster_3.3-7 webshot_0.5.2 scales_1.1.1
## [21] processx_3.4.2 RANN_2.6.1 satellite_1.0.2 tibble_3.0.1
## [25] generics_0.0.2 ellipsis_0.3.1 withr_2.2.0 cli_2.0.2
## [29] magrittr_1.5 crayon_1.3.4 memoise_1.1.0 evaluate_0.14
## [33] ps_1.3.3 fs_1.4.1 fansi_0.4.1 xml2_1.3.2
## [37] class_7.3-16 pkgbuild_1.0.8 tools_4.0.0 prettyunits_1.1.1
## [41] hms_0.5.3 lifecycle_0.2.0 stringr_1.4.0 munsell_0.5.0
## [45] callr_3.4.3 compiler_4.0.0 e1071_1.7-3 rlang_0.4.6
## [49] classInt_0.4-3 units_0.6-6 grid_4.0.0 htmlwidgets_1.5.1
## [53] crosstalk_1.1.0.1 igraph_1.2.5 leafem_0.1.1 base64enc_0.1-3
## [57] rmarkdown_2.3 testthat_2.3.2 gtable_0.3.0 codetools_0.2-16
## [61] DBI_1.1.0 R6_2.4.1 rprojroot_1.3-2 KernSmooth_2.23-16
## [65] desc_1.2.0 stringi_1.4.6 Rcpp_1.0.4.6 vctrs_0.3.0
## [69] png_0.1-7 leaflet_2.0.3 tidyselect_1.1.0 xfun_0.14
Get a list of available StreamCat values for certain parameters using the get_streamcat_params function (right now just metric names and areas of interest for this function) via the API
area_params <- get_streamcat_params(param='area')
name_params <- get_streamcat_params(param='name')
print(paste0('Area of interest available parameters are: ', paste(area_params,collapse = ', ')))
## [1] "Area of interest available parameters are: catchment, watershed, riparian_catchment, riparian_watershed, other"
print(paste0('A selection of available StreamCat metrics include: ',paste(name_params[1:10],collapse = ', ')))
## [1] "A selection of available StreamCat metrics include: rddens, pctglaclakefine, tmax8110, pcthbwet2011, pcturbmd2001, pcturbmd2006, pctglactilloam, rdcrs, pcthay2006, pctfire2007"
Access several variables for several areas of interest and a couple COMIDs using theh get_streamcat_data function. Loads data into a tibble we can view.
df <- get_streamcat_data(metric='PctUrbMd2006,DamDens,TRIDens', aoi='riparian_catchment,catchment,watershed', comid='179,1337,1337420')
## &name=PctUrbMd2006,DamDens,TRIDens&comid=179,1337,1337420&areaOfInterest=riparian_catchment,catchment,watershed
kable(df)
| COMID | CATAREASQKM | WSAREASQKM | CATAREASQKMRP100 | TRIDENSCATRP100 | PCTURBMD2006CATRP100 | TRIDENSCAT | TRIDENSWS | PCTURBMD2006CAT | PCTURBMD2006WS | DAMDENSCAT | DAMDENSWS |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1337 | 2.5803 | 2.5803 | 0.2781 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.0000000 |
| 179 | 3.5550 | 3.5550 | 0.5373 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.0000000 |
| 1337420 | 3.4101 | 60.8517 | 0.2925 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.0328668 |
We can actually pull data into R from the StreamCat API by simply using read_csv function from the readr package. We have to hard-wire paramaters and are limited in number of records returned through a GET request
df <- read_csv("http://v26267mcpk506/StreamCat/v1/stable/metrics?name=fert&areaOfInterest=watershed&comid=179")
kable(df)
| COMID | WSAREASQKM | FERTWS |
|---|---|---|
| 179 | 3.555 | 1.437975 |
Access a couple watershed-only variables for a county (Benton County in this case) using the get_streamcat_data function.
df <- get_streamcat_data(metric='PctWdWet2006', aoi='watershed', county='41003')
## &name=PctWdWet2006&areaOfInterest=watershed&county=41003
kable(head(df))
| COMID | FIPS | WSAREASQKM | PCTWDWET2006WS |
|---|---|---|---|
| 23764519 | 41003 | 12.5856 | 0.3432494 |
| 23762751 | 41003 | 213.6753 | 1.0959620 |
| 23763039 | 41003 | 5.8509 | 2.9380095 |
| 23762873 | 41003 | 13.6341 | 0.6601096 |
| 23763313 | 41003 | 81.8478 | 0.5146137 |
| 23763023 | 41003 | 19.9863 | 2.4992120 |
Access a couple watershed-only metrics for a particular hydroregion using the get_streamcat_data function.
df <- get_streamcat_data(metric='PctWdWet2006', aoi='watershed', region='17')
## &name=PctWdWet2006&areaOfInterest=watershed®ion=17
kable(head(df))
| COMID | REGIONID | WSAREASQKM | PCTWDWET2006WS |
|---|---|---|---|
| 24345567 | Region17 | 6.9354 | 2.0503504 |
| 24345937 | Region17 | 0.9306 | 46.2282398 |
| 24345643 | Region17 | 7.3746 | 0.0000000 |
| 24345671 | Region17 | 1.1871 | 0.0000000 |
| 24345803 | Region17 | 94.5153 | 0.3056648 |
| 24345549 | Region17 | 1.7847 | 0.0000000 |
Access a single variable for the Calapooia River using get_streamcat_data function. Use nhdplusTools library to grab flowlines and watershed for the Calapooia, plot selected StreamCat metric for Calapooia and show the watershed.
discover_nldi_sources()$source
## [1] "comid" "huc12pp" "nwissite" "wade" "WQP"
start_comid = 23763529
nldi_feature <- list(featureSource = "comid", featureID = start_comid)
discover_nldi_navigation(nldi_feature)
## $upstreamMain
## [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/23763529/navigate/UM"
##
## $upstreamTributaries
## [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/23763529/navigate/UT"
##
## $downstreamMain
## [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/23763529/navigate/DM"
##
## $downstreamDiversions
## [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/23763529/navigate/DD"
flowline_nldi <- navigate_nldi(nldi_feature, mode = "upstreamTributaries", data_source = "")
# get StreamCat metrics
temp_dir <- 'C:/Users/mweber/temp'
nhdplus <- subset_nhdplus(comids = flowline_nldi$nhdplus_comid, output_file = file.path(temp_dir, "nhdplus.gpkg"),nhdplus_data = "download",overwrite = TRUE, return_data = FALSE)
st_layers(nhdplus)
## Driver: GPKG
## Available layers:
## layer_name geometry_type features fields
## 1 NHDFlowline_Network 3D Multi Line String 187 91
## 2 CatchmentSP Multi Polygon 186 8
## 3 NHDArea Multi Polygon 6 16
## 4 NHDWaterbody Multi Polygon 17 23
cats <- read_sf(dsn=nhdplus, layer='CatchmentSP')
comids <- paste(cats$featureid,collapse=",",sep="")
df <- get_streamcat_data(metric='PctImp2011', aoi='catchment', comid=comids)
## &name=PctImp2011&comid=23765999,23763555,23763615,23763651,23763585,23763623,23763863,23763649,23763805,23763655,23763563,23763559,23763677,23763813,23763641,23763581,23763551,23763575,23763659,23763803,23763605,23763807,23763531,23763625,23763537,23763635,23763637,23763675,23763535,23763865,23763657,23763631,23763811,23763561,23763619,23763593,23763611,23763533,23763665,23763543,23763629,23763547,23763609,23763819,23763645,23763643,23763587,23763597,23763573,23763621,23763599,23763663,23763673,23763539,947090059,23763867,23763579,23763589,23763591,23763861,23763821,23763549,23763601,23763557,23763577,23763617,23763571,23763639,23763671,23763545,23763529,23763553,23763681,23763661,23763567,23763679,23763607,23763613,23763569,23763817,23763667,23763669,23763603,23763647,23763565,23763815,23763583,23763627,23763633,23763653,23763595,23765135,23765143,23765159,23764969,23765173,23765163,23765191,23765097,23765251,23764843,23765179,23765203,23765033,23765083,23765193,23765167,23765247,23765165,23764987,23765087,23765201,23764867,23764967,23764989,23764917,23765037,23764849,23765287,23764797,23764907,23765323,23764949,23764889,23765171,23765055,23765045,23765001,23765195,23765069,23765003,23764901,23764815,23764783,23764999,23765151,23764995,23764979,23765105,23765117,23764961,23765199,23765127,23765189,23765067,23765175,23764919,23765099,23765075,23765015,23764687,23764963,23764943,23765073,23764751,23765053,23765041,23765267,23765297,23765241,23765341,23765309,23765311,23765339,23765343,23765239,23765229,23765249,23765235,23765227,23765301,23765277,23765215,23765273,23765221,23765299,23765223,23765225,23765233,23765291,23765295,23765319,23765243,23765275,23765285,23765279&areaOfInterest=catchment
flowline_nldi$PCTIMP2011CAT <- df$PCTIMP2011CAT[match(flowline_nldi$nhdplus_comid, df$COMID)]
basin <- get_nldi_basin(nldi_feature = nldi_feature)
mapview(basin, alpha.regions=.08) + mapview(flowline_nldi, zcol = "PCTIMP2011CAT", legend = TRUE)
Grab NRSA data from NARS website directly in R, pull particular StreamCat metrics for sites using get_streamcat_data, and compare landscape metrics with other NRSA metrics
nrsa <- read_csv('https://www.epa.gov/sites/production/files/2015-09/siteinfo_0.csv')
glimpse(nrsa)
## Rows: 2,320
## Columns: 34
## $ PUBLICATION_DATE <chr> "9/1/2015", "9/1/2015", "9/1/2015", "9/1/2015", "9...
## $ UID <dbl> 10000, 10001, 10002, 10003, 10004, 10006, 10007, 1...
## $ SITE_ID <chr> "FW08KS001", "FW08KS003", "FW08KS005", "FW08KS006"...
## $ YEAR <dbl> 2008, 2008, 2008, 2008, 2008, 2008, 2008, 2008, 20...
## $ VISIT_NO <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 2,...
## $ DATE_COL <chr> "5-Aug-08", "11-Aug-08", "22-Jul-08", "12-Aug-08",...
## $ STATE <chr> "KS", "KS", "KS", "KS", "KS", "KS", "KS", "LA", "D...
## $ LOC_NAME <chr> "Twelvemile Creek", "Turkey Creek", "Thomas Creek"...
## $ SITE_CLASS <chr> "PROB", "PROB", "PROB", "PROB", "PROB", "PROB", "P...
## $ AGGR_ECO3_2015 <chr> "PLNLOW", "PLNLOW", "PLNLOW", "PLNLOW", "PLNLOW", ...
## $ AGGR_ECO9_2015 <chr> "SPL", "SPL", "TPL", "SPL", "TPL", "SPL", "TPL", "...
## $ ECO10 <chr> NA, "PL-RANGE", NA, NA, NA, NA, NA, NA, NA, "PL-NC...
## $ US_L3CODE_2015 <dbl> 27, 26, 40, 27, 28, 27, 40, 35, 63, 25, 63, 63, 13...
## $ US_L4CODE_2015 <chr> "27a", "26a", "40b", "27d", "28a", "27c", "40b", "...
## $ EPA_REG <dbl> 7, 7, 7, 7, 7, 7, 7, 6, 3, 7, 3, 3, 9, 9, 9, 9, 9,...
## $ LAT_DD83 <dbl> 39.01491, 37.39528, 38.19893, 37.47702, 37.78662, ...
## $ LON_DD83 <dbl> -98.01046, -98.92628, -95.42768, -98.36534, -96.42...
## $ HUC8 <dbl> 10260010, 11060003, 10290101, 11060005, 11070102, ...
## $ URBAN <chr> "NonUrban", "NonUrban", "NonUrban", "NonUrban", "N...
## $ STRAHLERORDER <chr> "2nd", "3rd", "2nd", "3rd", "4th", "7th", "1st", "...
## $ MISS_SUB <chr> "Lower Missouri Region", "Arkansas-White-Red Regio...
## $ LMR_SITE <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ GREAT_RIVER <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ RT_NRSA <chr> "S", "R", "T", "S", "R", "T", "T", "S", "S", "S", ...
## $ RT_NRSA_FISH <chr> "S", "R", "T", "S", "R", "T", "T", "S", NA, "S", "...
## $ RT_NRSA_PHAB <chr> "T", "R", "T", "S", "S", "S", "T", "S", "S", "S", ...
## $ RT_NRSA_CAT <chr> "Intermediate Disturbance", "Least Disturbed", "Mo...
## $ XLAT_DD <dbl> 39.01489, 37.39529, 38.19898, 37.47713, 37.78643, ...
## $ XLON_DD <dbl> 98.01056, 98.92609, 95.42765, 98.36481, 96.42996, ...
## $ WGTNRSA09 <dbl> 401.03253, 516.69685, 1217.68103, 516.69685, 2029....
## $ MASTER_SITEID <chr> "OWW04440-0595", "OWW04440-0163", "OWW04440-0115",...
## $ INDEX_VISIT <chr> "YES", "YES", "YES", "YES", "YES", "YES", "YES", "...
## $ INDEXVIS_FTIS <chr> NA, NA, NA, NA, NA, "YES", NA, "YES", NA, "YES", N...
## $ WSAREA_NARS <dbl> 22.32040, 168.24600, 19.97650, 141.51401, 101.5940...
# Promote data frame to sf spatial points data frame
nrsa_sf <- st_as_sf(nrsa, coords = c("LON_DD83", "LAT_DD83"), crs = 4269)
# Get COMIDs using nhdplusTools package
# nrsa$COMID<- NA
# for (i in 1:nrow(nrsa_sf)){
# print (i)
# nrsa_sf[i,'COMID'] <- discover_nhdplus_id(nrsa_sf[i,c('geometry')])
# }
load("L:/Public/mweber/example.RData")
# get particular StreamCat data for all these NRSA sites
# nrsa_sf$COMID <- as.character(nrsa_sf$COMID)
comids <- nrsa_sf$COMID
comids <- comids[!is.na(comids)]
comids <- comids[c(1:925)]
comids <- paste(comids,collapse=',')
df <- get_streamcat_data(metric='PctCrop2006', aoi='watershed', comid=comids)
## &name=PctCrop2006&comid=18865370,21012349,10125204,20983869,21515712,22082845,3646540,17917807,8391876,21249994,4653422,4651294,11174355,23198924,11174355,10787024,10787024,10693689,23335952,23198686,20594352,23287531,11187793,24061295,10749941,10774418,11206810,11206810,11851079,11139018,11281846,11338977,10785790,20624320,11390644,11154545,11208384,23287337,11848891,11125011,8920063,11157333,948020862,11207100,23287029,11851763,11432215,20294501,10763433,11203330,10762675,11135436,11198470,11227624,11179295,946040194,23198924,4442592,8270711,7978069,4439896,4442410,2820014,2706253,15024989,362143,24528218,23659640,23824881,24207875,23889622,24224945,23876833,23894328,947100116,23785691,23785691,23886302,23893976,23763423,23880848,23760158,23780491,22226490,23902339,23671143,23763329,24208825,23940179,23772873,23772873,24526820,23671695,23780461,3262587,3262587,5312628,5312628,3175206,191839,192089,934818,228553,18278757,191819,1595563,5312032,3232663,3232663,1321066,2888850,5239022,17876523,11699220,9772755,1837075,10968697,10968697,13584484,10607548,13438255,13785746,14771732,13785708,13608862,10608888,13554837,13426433,6083515,4599835,4577670,6083645,10102618,5785441,5511974,5778961,1015993,5523904,5588716,5279658,18461820,3984064,18498560,15672757,18445592,18461820,18445592,12262804,18508612,10205701,18490834,18439262,18487754,13437933,18507728,18470758,12257114,12261122,3922231,12264588,10083026,18487638,12255494,9005029,13008982,9005833,13015191,12242722,12242108,13194304,10850232,12130714,12135392,12232132,12134936,11929870,12186645,12960535,12133526,9008281,13311083,13311083,3701598,3701598,14621764,6947598,7017203,3701696,13210986,22475927,2500595,13325132,19210063,19165707,6598104,14624806,6590816,6950508,13312105,6621012,22252143,13313051,5137309,18450053,18464804,904060095,12952968,12134842,12121292,12116572,9005029,6582036,937010765,10597422,2353858,12952866,4252746,10597376,4141632,2441760,22702780,7764647,7805589,15236258,21923571,2387062,2645588,1100776,1104280,4652178,4652178,8392686,8392686,8392388,10853441,896637,448560,2242133,2135268,1978632,2248075,6497212,6494660,6498060,6365530,15808733,2723273,6603368,18061866,19268286,938060154,19269466,19269168,19269130,19269936,19269144,19268252,19266232,18059676,11909178,11909178,8392364,22337801,8448522,14363934,4507500,4507412,5891916,5894782,22341047,4507406,8392364,8431624,8401909,22340887,12421177,12421177,4264568,4264568,4222526,24319374,12620920,12416793,22977664,4363976,12605829,4061394,12730415,238848,24293784,12420943,12770867,4320118,12416635,7196759,24349930,4167508,24357677,12617812,24349962,12443813,13235093,7184590,12444631,2587891,6245974,4151692,2590217,2583245,6245648,9513050,2587891,12443887,4595083,4595083,9331576,9331576,9331392,6741776,9332538,6761938,4592867,9327714,6742014,9331302,7471678,14191085,14189961,18055942,18057726,938010358,7476356,7470420,7469390,7470402,14191031,18055920,18057758,7477806,14190011,14189953,18055956,14191053,14189935,14197799,18063208,7470394,7470416,7470320,7474808,7471678,7471668,7474818,7474854,5867107,5867107,6126589,6126589,9343409,9343409,6129881,6745786,7692197,6782191,6126589,22288391,15493002,22297330,15445207,21975043,8969900,15455920,15455920,22026450,9521357,6185902,15466705,3246788,6212224,8119227,9422951,8119227,7469382,21977225,9422951,21974619,932020090,9423999,15449228,22288395,15485147,6189052,8969946,8103053,22745845,9423281,932020140,22306077,15539403,21972796,6189276,22746575,21974543,21979451,7700796,7714150,1701588,1701588,4287419,4287419,5845376,3323290,1735618,1735618,5194912,1023634,720058,816563,4288323,3320216,4287139,4287817,1713416,2678134,4289195,4287139,1719869,3325392,6712643,3322526,16071540,11550378,11550378,16074364,21831213,16097365,21831539,11547252,5458404,21832875,14396444,21831311,12556972,14492810,940130676,16096497,16187292,14552817,14399396,4084278,5459476,16073476,16095563,14376633,8153841,21832339,11530735,12583589,22592131,15022523,15022523,8922673,17607469,359295,8914957,17568579,8315767,2810225,22050309,8028376,14571158,14518643,11473840,14414979,14415343,14156586,14569800,9789690,16235901,16203718,14172567,14145293,16224157,16224157,14569798,14569798,16246991,21861500,16213846,16235093,16248881,940110250,14254775,16248137,14482496,14519767,21850289,14428870,21860466,14439196,16223619,16223373,16247357,16214516,14143923,11473840,14682348,14518643,16214196,6696842,16223641,14567692,16203260,21873485,14828151,17393170,17512368,16101059,17431128,16032144,16056306,19043411,17448647,19062896,11655378,16068263,19095613,16032104,16051700,16031766,17405525,17825906,17844562,20059534,17865334,20039912,22460201,20817334,17877889,20065177,20044804,17015697,20025279,20024071,13859134,17864758,20853647,17863214,20031695,1875011,1875011,13357546,13634077,2456568,13330932,14732254,13296008,13098604,14717012,14717012,13208894,14728678,13625743,13283896,9027987,13123024,13412604,13296190,14709954,13085653,1813331,6810610,10422442,13585476,13439281,5089716,22077841,19017115,5926470,11866612,3644256,18879960,21160591,7347781,10115436,15968351,17483639,9587898,3414090,3387233,9573743,5424215,18276277,5422423,5377694,9593514,10904471,5377516,17483621,9388471,17495693,15961724,5412291,5358816,2521584,3379071,7913960,7913960,14597511,4900971,3507383,3199234,10023464,4876421,23176941,10807265,10092650,10807861,3910469,666156,3199328,4902157,10806051,10024662,1169814,3277705,7882406,3906307,17844562,6667869,15594599,8546607,5908303,8550019,8550019,8539107,8539107,8526555,1088175,8572603,6907937,6910095,8520617,6908415,8625173,14640373,8490226,1492208,1278566,1490758,2578249,5574915,5757682,1165033,1440185,3134061,4577592,4590501,9332550,9332550,6084477,4578832,4578832,6084609,4578848,6086593,4578132,10103928,10294286,23081454,24505412,24423157,23099594,15083581,17917807,19916928,19474563,19373816,19945005,1136232,19919288,15222340,19280778,19374362,19918026,15145788,15088127,17825906,4577670,8088885,8088885,2604777,4725099,8145244,2600155,4197434,8145208,5218065,19388310,5217151,15363363,5231404,15379381,9858973,5215271,5231404,15379381,19389930,3940470,15385429,3489643,15612806,13154255,3883720,15401056,3985854,5212175,11883580,14643159,14643159,19754221,19754221,19752219,19722605,3577878,3577878,22144680,22144680,19516944,22132893,19488822,18408586,22143538,19594674,19503026,22144762,19516176,19531274,19484892,22540552,12889889,24242137,23638212,23097070,24382869,19085477,25732008,19085479,19086179,19085519,22814383,19086185,22798749,19088123,19085501,22798749,22799299,22798749,19086949,19085455,19086167,19414571,435500,19321367,19321367,19293142,6925255,19314616,19414149,3768860,15431946,19314966,435346,9316901,2242019,2509085,5057167,3703114,7371325,2333107,7669218,5108252,7499184,5040296,5155983,4390553,7390081,3077713,20412668,20379235,3078075,21331223,21357181,4997861,5104956,5136677,20906127,11700806,745529,3729225,7522059,7446467,5441900,16100983,16068221,19080501,4020363,16249437,18841300,23630682,23630682,24177529,24177529,23156470,23284675,23533481,24493982,23387311,23283585,23513704,23196240,4558716,23267350,24159945,12520543,12641653,16248969,12462696,15905101,3077713,15890430,16213090,16247407,2888730,18604722,18696205,18118648,15701805,15890430,21322721,21356971,21351925,19645438,19598502,19598508,4655356,18466372,18449963,18476809,18498654,18482604,18474767,13189972,18490272,19939823,21906227,19919742,938080179,19432872,3710332,19349145,19432862,19369742,8342369,7751684,7756138,7802359,7629788,7763911,7817572,21920301,15238480,7827470,12320303,538279,5262424,380740,683473,425068,532475,559903,3142124,372489,430066,535655,5380432,5366525,5372569,10907263,12645465,14569240,21848339,21533134,21066552,21027224,673110,683473,21223919,3646864,14521095,3473045,12021208,9019417,6859814,12242058,3472557,6860660,19969876,19969876,1128303,11959884,3467441,15706711,15687155,15739485,18108068,5513784,12656405,9305368,13882602,3596702,13605756,10338064,2930189,10146295&areaOfInterest=watershed
glimpse(df)
## Rows: 854
## Columns: 3
## $ COMID <dbl> 23824881, 23659640, 24505412, 23671143, 24061295, 222...
## $ WSAREASQKM <dbl> 17.5959, 82.6686, 35.0226, 214.3953, 11.8953, 38.8116...
## $ PCTCROP2006WS <dbl> 0.00000000, 1.68963790, 0.00000000, 0.00000000, 0.000...
df$COMID <- as.integer(df$COMID)
nrsa_sf <- left_join(nrsa_sf, df, by='COMID')
# download mmi from NARS web page
mmi <- read_csv('https://www.epa.gov/sites/production/files/2015-09/bentcond.csv')
glimpse(mmi)
## Rows: 2,320
## Columns: 39
## $ PUBLICATION_DATE <chr> "9/2/2015", "9/2/2015", "9/2/2015", "9/2/2015", "9...
## $ UID <dbl> 10000, 10001, 10002, 10003, 10004, 10006, 10007, 1...
## $ SITE_ID <chr> "FW08KS001", "FW08KS003", "FW08KS005", "FW08KS006"...
## $ VISIT_NO <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 2,...
## $ YEAR <dbl> 2008, 2008, 2008, 2008, 2008, 2008, 2008, 2008, 20...
## $ DATE_COL <chr> "5-Aug-08", "11-Aug-08", "22-Jul-08", "12-Aug-08",...
## $ AGGR_ECO9_2015 <chr> "SPL", "SPL", "TPL", "SPL", "TPL", "SPL", "TPL", "...
## $ SAMPLE_TYPE <chr> "BENT", "BENT", "BENT", "BENT", "BENT", "BENT", "B...
## $ BENT_SAMPLE_TYPE <chr> "BERWW", "BERWW", "BERWW", "BERWW", "BERWW", "BERW...
## $ BENT_MMI_COND <chr> "Good", "Good", "Poor", "Poor", "Good", "Fair", "P...
## $ OE_COND <chr> "O/E>0.9", "O/E<0.5", "O/E<0.8", "O/E<0.5", "O/E>0...
## $ SAMPLED_BENT <chr> "YES", "YES", "YES", "YES", "YES", "YES", "YES", "...
## $ MMI_BENT <dbl> 39.60, 50.93, 17.30, 15.68, 77.17, 25.65, 25.58, 1...
## $ OE_SCORE <dbl> 1.1746892, 0.4383902, 0.7245665, 0.2744488, 1.2652...
## $ COMP_PT <dbl> 5.05, 6.53, 0.06, 0.98, 7.58, 3.26, 0.75, 2.63, 1....
## $ DIVS_PT <dbl> 6.82, 6.59, 3.98, 0.00, 7.16, 4.45, 4.66, 4.02, 5....
## $ FEED_PT <dbl> 2.86, 5.71, 3.75, 0.00, 6.25, 0.00, 5.00, 2.50, 2....
## $ HABT_PT <dbl> 2.84, 4.11, 0.59, 3.57, 8.82, 7.01, 2.94, 0.00, 3....
## $ RICH_PT <dbl> 3.33, 3.33, 2.00, 2.00, 9.00, 0.67, 2.00, 0.00, 3....
## $ TOLR_PT <dbl> 2.86, 4.29, 0.00, 2.86, 7.49, 0.00, 0.00, 2.05, 4....
## $ BURRPTAX <dbl> 27.27, 23.33, NA, 25.00, NA, 14.29, NA, NA, NA, 26...
## $ CHIRPTAX <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ CLNGNTAX <dbl> NA, NA, 4, NA, 18, NA, 8, NA, NA, NA, NA, NA, NA, ...
## $ CLNGPTAX <dbl> NA, NA, NA, NA, NA, NA, NA, 13.64, 26.83, NA, 23.2...
## $ DOM5PIND <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 91...
## $ EPHENTAX <dbl> NA, NA, 3, NA, 10, NA, 3, NA, NA, NA, NA, NA, NA, ...
## $ EPHEPTAX <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ EPT_NTAX <dbl> 6, 6, NA, 4, NA, 2, NA, 1, 7, 4, 3, 3, 3, 14, 2, 1...
## $ EPT_PIND <dbl> 33.67, 43.33, 1.17, 7.10, 61.00, 22.00, 6.67, NA, ...
## $ EPT_PTAX <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ HPRIME <dbl> 2.60, 2.55, 2.11, 0.70, 2.67, 2.10, 2.23, 2.30, 2....
## $ INTLNTAX <dbl> 3, 4, NA, 3, NA, 1, NA, NA, NA, 2, NA, NA, NA, NA,...
## $ NOINPIND <dbl> NA, NA, NA, NA, NA, NA, NA, 54.00, 61.67, NA, 21.0...
## $ NTOLNTAX <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ NTOLPTAX <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
## $ SCRPNTAX <dbl> 3, 5, 4, 1, 6, 1, 5, NA, NA, 1, NA, NA, 2, 4, 4, 6...
## $ SHRDNTAX <dbl> NA, NA, NA, NA, NA, NA, NA, 3, 3, NA, 4, 2, NA, NA...
## $ STOLPTAX <dbl> NA, NA, 34.78, NA, 11.63, NA, 42.31, NA, NA, NA, N...
## $ TOLRPTAX <dbl> NA, NA, NA, NA, NA, NA, NA, 40.91, 31.71, NA, 37.2...
# join mmi to NARS info data frame with StreamCat PctCrop metric
nrsa_sf <- left_join(nrsa_sf, mmi[,c('SITE_ID','BENT_MMI_COND')], by='SITE_ID')
nrsa_sf %>%
drop_na(BENT_MMI_COND) %>%
ggplot(aes(x=PCTCROP2006WS, y=BENT_MMI_COND))+
geom_boxplot()