Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

plot model performance #181

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 1_fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ source("1_fetch/src/fetch_nhdv2_attributes_from_sb.R")

p1_targets_list <- list(

# Track and read in the state boundaries sf object. This file was
# created by running `states <- get_state_shp()` followed by
# `saveRDS(states, "1_fetch/in/state_boundaries.rds)`. get_state_shp
# is from 3_visualize/src/map_sites.R. It depends on the USAboundaries
# package, which is currently archived on CRAN.
tar_target(
p1_state_boundaries_rds,
"1_fetch/in/state_boundaries.rds",
format = "file"
),
tar_target(
p1_state_boundaries_sf,
readRDS(p1_state_boundaries_rds)
),

# download WQP data product from science base for discrete samples
tar_target(
p1_wqp_data_file,
Expand Down
Binary file added 1_fetch/in/state_boundaries.rds
Binary file not shown.
1 change: 1 addition & 0 deletions 3_visualize.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ p3_targets_list <- list(
p3_site_map_png,
map_sites(flowlines = p1_nhd_reaches_sf,
matched_sites = p2a_site_splits,
states_shp = p1_state_boundaries_sf,
out_file = "3_visualize/out/do_site_map.png")
),

Expand Down
29 changes: 20 additions & 9 deletions 3_visualize/src/map_sites.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' @param matched_sites sf object containing site locations and the flowline
#' reach identifier ("COMID") that the site has been matched to. Must contain
#' columns "COMID" and "geometry".
#' @param states_shp sf object containing the U.S. state boundaries to
#' include in the watershed plot.
#' @param out_file character string indicating the name of the saved file,
#' including file path and extension.
#' @param huc6_select vector of character string(s) indicating the HUC6 basins that
Expand Down Expand Up @@ -37,6 +39,7 @@
#'
map_sites <- function(flowlines,
matched_sites,
states_shp,
out_file,
huc6_select = "020402",
basin_bbox = c(xmin = -76.39556, ymin = 39.5, xmax = -74.37121, ymax = 40.89106),
Expand Down Expand Up @@ -109,7 +112,7 @@ map_sites <- function(flowlines,
ggspatial::annotation_scale(bar_cols = c("gray70","white"))

# create inset map
inset_map <- map_drb_watershed(matched_sites)
inset_map <- map_drb_watershed(matched_sites, states_shp = states_shp)

# grab legend
legend <- cowplot::get_legend(sites_map)
Expand Down Expand Up @@ -145,10 +148,6 @@ map_sites <- function(flowlines,
#' @param huc8 vector of character string(s) indicating the HUC8 basins that
#' make up the watershed of interest. By default, the HUC8 basins that make up
#' the Delaware River Basin will be used.
#' @param states vector of character string(s) indicating which states should
#' be included in the inset map, using two-letter postal code abbreviations for
#' each state. By default, the states surrounding the Delaware River Basin will
#' be downloaded, including "NY", "PA", "NJ", "DE", and "MD".
#' @param epsg_out integer indicating the coordinate reference system that
#' should be used when creating the inset map. Defaults to EPSG 3857, pseudo-
#' mercator: https://epsg.io/3857
Expand All @@ -157,17 +156,14 @@ map_sites <- function(flowlines,
#' Returns an inset map as a ggplot object.
#'
map_drb_watershed <- function(sites,
states_shp,
huc8 = c("02040101","02040102","02040103",
"02040104","02040105","02040106",
"02040201","02040202","02040203",
"02040204","02040205","02040206",
"02040207"),
states = c("NY","PA","NJ","DE","MD"),
epsg_out = 3857){

# Download shapefiles for states that encompass the watershed of interest
states_shp <- USAboundaries::us_states(resolution = "high", states = states)

# Download HUC8 boundaries associated with watershed boundary
boundary <- nhdplusTools::get_huc8(id = huc8) %>%
sf::st_union()
Expand All @@ -191,6 +187,21 @@ map_drb_watershed <- function(sites,
}


#' @title Download state shapefiles
#'
#' @param states vector of character string(s) indicating which states should
#' be included in the inset map, using two-letter postal code abbreviations for
#' each state. By default, the states surrounding the Delaware River Basin will
#' be downloaded, including "NY", "PA", "NJ", "DE", and "MD".
#'
get_state_shp <- function(states = c("NY","PA","NJ","DE","MD")){

# Download shapefiles for states that encompass the watershed of interest
states_shp <- USAboundaries::us_states(resolution = "high", states = states)

}


#' @title Create leaflet map of site locations

#' @description
Expand Down
Loading