| Title: | Hydrologic AnalySis Package |
|---|---|
| Description: | Data aggregation and plotting of USGS groundwater level data. |
| Authors: | Laura DeCicco [aut, cre] (ORCID: <https://orcid.org/0000-0002-3915-9487>), Scott Prinos [aut] (ORCID: <https://orcid.org/0000-0002-5776-8956>), Patrick Eslick-Huff [aut] (ORCID: <https://orcid.org/0000-0003-2611-6012>), Candice Hopkins [aut] (ORCID: <https://orcid.org/0000-0003-3207-7267>), Lindsay Platt [ctr], Tara Root [ctr] |
| Maintainer: | Laura DeCicco <[email protected]> |
| License: | CC0 |
| Version: | 1.0.4.9000 |
| Built: | 2026-05-26 22:19:29 UTC |
| Source: | https://code.usgs.gov/water/stats/HASP |
Example data representing Basin and Range basin-fill aquifers (N100BSNRGB).
head(aquifer_data) head(site_info)head(aquifer_data) head(site_info)
Create composite data
composite_data(x, num_years, parameter_cd)composite_data(x, num_years, parameter_cd)
x |
aquifer data |
num_years |
integer number of years required |
parameter_cd |
character, 5-digit parameter code, default is "72019". |
data frame with year, name, and value
aquifer_data <- aquifer_data num_years <- 30 comp_data <- composite_data(aquifer_data, num_years, "72019")aquifer_data <- aquifer_data num_years <- 30 comp_data <- composite_data(aquifer_data, num_years, "72019")
Opens a template of the blanks sample report. Running the function will create a Rmd file. The file can be "knit" as-is, or adjusted before rendering.
create_groundwater_report( siteID, report_name, report_folder, output_type = "word" )create_groundwater_report( siteID, report_name, report_folder, output_type = "word" )
siteID |
character. USGS site ID, should be a groundwater site. |
report_name |
character. Base name of report. |
report_folder |
character. Report folder, can be full path or partial. |
output_type |
should be either "word", "html", or "pdf". |
## Not run: create_groundwater_report("USGS-253029080295601", report_name = "example_report", report_folder = "reports", output_type = "word") create_groundwater_report("USGS-253029080295601", report_name = "example_report", report_folder = "reports", output_type = "html") ## End(Not run)## Not run: create_groundwater_report("USGS-253029080295601", report_name = "example_report", report_folder = "reports", output_type = "word") create_groundwater_report("USGS-253029080295601", report_name = "example_report", report_folder = "reports", output_type = "html") ## End(Not run)
Opens a template of the blanks sample report. Running the function will create a Rmd file.
create_targets_script( national_aquifer_cd, parameter_cd = "72019", statistic_cd = "00003", start_date, end_date, file_name = "_targets.R" )create_targets_script( national_aquifer_cd, parameter_cd = "72019", statistic_cd = "00003", start_date, end_date, file_name = "_targets.R" )
national_aquifer_cd |
character. |
parameter_cd |
character. |
statistic_cd |
character. |
start_date |
character. |
end_date |
character. |
file_name |
description |
## Not run: create_targets_script(national_aquifer_cd = "N100BSNRGB", parameter_cd = "72019", statistic_cd = "00003", start_date = "1988-10-01", end_date = "2021-01-01", file_name = "_targets_test.R") ## End(Not run)## Not run: create_targets_script(national_aquifer_cd = "N100BSNRGB", parameter_cd = "72019", statistic_cd = "00003", start_date = "1988-10-01", end_date = "2021-01-01", file_name = "_targets_test.R") ## End(Not run)
Calculates the historical max, mean, minimum, and number of available points for each day of the year
daily_frequency_table( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status") )daily_frequency_table( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status") )
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
gwl_data |
data frame returned from |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
a data frame giving the max, mean, min, and number of available days of data for each day of the year.
site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily daily_frequency_table(gw_level_dv, NULL, parameter_cd = "62610") # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete daily_frequency_table(gw_level_dv, gwl_data, parameter_cd = "62610")site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily daily_frequency_table(gw_level_dv, NULL, parameter_cd = "62610") # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete daily_frequency_table(gw_level_dv, gwl_data, parameter_cd = "62610")
Calculates daily statistics based on all approved data. Daily, discrete, or both types are included. Historic median or mean are plotted based on all of the approved data.
daily_gwl_plot( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), historical_stat = "mean", month_breaks = TRUE, plot_title = "", plot_range = "Past year", subtitle = "U.S. Geological Survey", y_axis_label = "", flip = FALSE )daily_gwl_plot( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), historical_stat = "mean", month_breaks = TRUE, plot_title = "", plot_range = "Past year", subtitle = "U.S. Geological Survey", y_axis_label = "", flip = FALSE )
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
gwl_data |
data frame returned from |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
historical_stat |
the summary statistic to use for middle line of the plot. Either "mean" or "median." |
month_breaks |
a logical indicating whether to use monthly breaks for the plot |
plot_title |
the title to use on the plot |
plot_range |
the time frame to use for the plot. Use "Past year" (default) to see the last year of data, or "Calendar year" to use the current calendar year, beginning in January. Or specify two dates representing the start and end of the plot. If the first date is NA, it will start at the earliest record, if the second date is NA, it will end at the latest record. |
subtitle |
character. Sub-title for plot, default is "U.S. Geological Survey". |
y_axis_label |
the label used for the y-axis of the plot. |
flip |
logical. If |
site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete daily_gwl_plot(gw_level_dv, NULL, plot_title = "Groundwater Level", historical_stat = "median") daily_gwl_plot(gw_level_dv, gwl_data, parameter_cd = "62610", plot_title = "Groundwater Level", historical_stat = "median") daily_gwl_plot(gw_level_dv, gwl_data, parameter_cd = "62610", plot_title = "Groundwater Level", month_breaks = TRUE, plot_range = c("2020-10-01", "2021-06-01"), historical_stat = "median")site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete daily_gwl_plot(gw_level_dv, NULL, plot_title = "Groundwater Level", historical_stat = "median") daily_gwl_plot(gw_level_dv, gwl_data, parameter_cd = "62610", plot_title = "Groundwater Level", historical_stat = "median") daily_gwl_plot(gw_level_dv, gwl_data, parameter_cd = "62610", plot_title = "Groundwater Level", month_breaks = TRUE, plot_range = c("2020-10-01", "2021-06-01"), historical_stat = "median")
Summary table of daily data
daily_gwl_summary( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status") )daily_gwl_summary( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status") )
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
gwl_data |
data frame returned from |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
a summary table giving the period of record, completeness and percentile values
site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily daily_gwl_summary(gw_level_dv, gwl_data = NULL, parameter_cd = p_code_dv) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete daily_gwl_summary(gw_level_dv, gwl_data = gwl_data, parameter_cd = p_code_dv)site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily daily_gwl_summary(gw_level_dv, gwl_data = NULL, parameter_cd = p_code_dv) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete daily_gwl_summary(gw_level_dv, gwl_data = gwl_data, parameter_cd = p_code_dv)
Get station summary information
data_available(siteID)data_available(siteID)
siteID |
character. USGS site ID for a groundwater site. |
siteID <- "USGS-263819081585801" site_data_available <- data_available(siteID)siteID <- "USGS-263819081585801" site_data_available <- data_available(siteID)
Open an interactive app in a browser. See the "Shiny App" vignette:
vignette("shinyApp", package = "toxEval") for more details. Using this
function is a quick and convenient way
to explore data. For more customization, the R-code to
produce each graph and table is displayed in the app. That is
a good starting-point for a custom analysis.
explore_aquifers(browse = TRUE) explore_site(browse = TRUE)explore_aquifers(browse = TRUE) explore_site(browse = TRUE)
browse |
Logical. Use browser for running Shiny app. |
## Not run: explore_aquifers() ## End(Not run) ## Not run: explore_site() ## End(Not run)## Not run: explore_aquifers() ## End(Not run) ## Not run: explore_site() ## End(Not run)
Filter down to sites with num_years of data
filter_sites( x, parameter_cd = "72019", num_years = NA, start_year = NA, end_year = NA )filter_sites( x, parameter_cd = "72019", num_years = NA, start_year = NA, end_year = NA )
x |
aquifer data |
parameter_cd |
character, 5-digit parameter code, default is "72019". |
num_years |
integer number of years required. This can be
|
start_year |
integer the first year to filter from. If |
end_year |
integer the last year to filter from. If |
data frame filter of x
aquifer_data <- aquifer_data num_years <- 30 aq_data <- filter_sites(aquifer_data, parameter_cd = "72019", num_years = num_years)aquifer_data <- aquifer_data num_years <- 30 aq_data <- filter_sites(aquifer_data, parameter_cd = "72019", num_years = num_years)
Find the first day of the month for a given date
first_day(date)first_day(date)
date |
a vector of dates |
the first day of the month that given dates fall in
date <- as.Date("2020-12-28") first_day(date)date <- as.Date("2020-12-28") first_day(date)
Get USGS data based on aquiferCd
get_aquifer_data(aquiferCd, startDate, endDate, parameter_cd = "72019")get_aquifer_data(aquiferCd, startDate, endDate, parameter_cd = "72019")
aquiferCd |
character. To see valid aquifer codes, see the included data
frame |
startDate |
date or string. Beginning date of when to pull data. |
endDate |
date of string Ending date to pull data. |
parameter_cd |
5-digit character USGS parameter code. |
end_date <- "2021-01-01" start_date <- "1989-12-31" aquiferCd <- "S100CSLLWD" # aq_data <- get_aquifer_data(aquiferCd, start_date, end_date)end_date <- "2021-01-01" start_date <- "1989-12-31" aquiferCd <- "S100CSLLWD" # aq_data <- get_aquifer_data(aquiferCd, start_date, end_date)
Get range
get_range(plot_range, full_range)get_range(plot_range, full_range)
plot_range |
the time frame to use for the plot. Use "Past year" (default) to see the last year of data, or "Calendar year" to use the current calendar year, beginning in January. Or specify two dates representing the start and end of the plot. |
full_range |
the full time range of the data. |
list of plot_start, plot_end, label
full_range <- c("2000-01-01", "2025-10-01") get_range("Past year", full_range) get_range("Calendar year", full_range) get_range(c("2024-10-01", "2025-06-01"), full_range) get_range(c(NA, "2020-01-01"), full_range) get_range(c("2020-01-01", NA), full_range)full_range <- c("2000-01-01", "2025-10-01") get_range("Past year", full_range) get_range("Calendar year", full_range) get_range(c("2024-10-01", "2025-06-01"), full_range) get_range(c(NA, "2020-01-01"), full_range) get_range(c("2020-01-01", NA), full_range)
Get USGS data based for a single state with specific aquifer codes.
get_state_data(state, aquiferCd, startDate, endDate, parameter_cd = "72019")get_state_data(state, aquiferCd, startDate, endDate, parameter_cd = "72019")
state |
character. Can be state abbreviation, long name, or numeric code. |
aquiferCd |
character. To see valid aquifer codes, see the included data
frame |
startDate |
date or string. Beginning date of when to pull data. |
endDate |
date of string Ending date to pull data. |
parameter_cd |
5-digit character USGS parameter code. Default is "72019". |
Function to create the field groundwater level data plot.
gwl_plot_field( gwl_data, plot_title = "", parameter_cd = NA, date_col = "time", value_col = "value", approved_col = "approval_status", flip = TRUE, y_label = "", subtitle = "U.S. Geological Survey" ) gwl_plot_all( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), y_label = "", subtitle = "U.S. Geological Survey", plot_title = "", add_trend = FALSE, n_years = 10, POR_trend = TRUE, flip = FALSE, days_required_per_month = 14 )gwl_plot_field( gwl_data, plot_title = "", parameter_cd = NA, date_col = "time", value_col = "value", approved_col = "approval_status", flip = TRUE, y_label = "", subtitle = "U.S. Geological Survey" ) gwl_plot_all( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), y_label = "", subtitle = "U.S. Geological Survey", plot_title = "", add_trend = FALSE, n_years = 10, POR_trend = TRUE, flip = FALSE, days_required_per_month = 14 )
gwl_data |
data frame returned from |
plot_title |
character, title for plot. |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
flip |
logical. If |
y_label |
character for y-axis label. Consider using
|
subtitle |
character. Sub-title for plot, default is "U.S. Geological Survey". |
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
add_trend |
logical. Uses |
n_years |
integer. This is the number of years to calculate the trend on. Default is 10. This can be a vector of years. |
POR_trend |
a logical indicating whether to include a trend test
for the full period of record. Default is |
days_required_per_month |
integer. Number of days required per month.
Default is 14. Only used if add_trend is |
site <- "USGS-263819081585801" # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete pcodes <- dataRetrieval::read_waterdata_parameter_codes( parameter_code = unique(gwl_data$parameter_code) ) gwl_plot_field(gwl_data, plot_title = "L2701_example", parameter_cd = "62610", flip = FALSE, y_label = pcodes$parameter_name[pcodes$parameter_code == "62610"]) gwl_plot_field(gwl_data, plot_title = "L2701_example", y_label = pcodes$parameter_name[pcodes$parameter_code == "62611"], parameter_cd = "62611", flip = FALSE) gwl_plot_field(gwl_data, plot_title = "L2701_example", y_label = pcodes$parameter_name[pcodes$parameter_code == "72019"], parameter_cd = "72019", flip = TRUE) site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily site_info <- dataRetrieval::read_waterdata_monitoring_location(monitoring_location_id = site) plot_title <- site_info$monitoring_location_name pcodes <- dataRetrieval::read_waterdata_parameter_codes(parameter_code = p_code_dv) gwl_plot_all(gw_level_dv, NULL, plot_title = plot_title, y_label = pcodes$parameter_name, flip = TRUE) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete gwl_plot_all(gw_level_dv, gwl_data, parameter_cd = "62610", plot_title = plot_title, y_label = pcodes$parameter_name, add_trend = FALSE, flip = FALSE) gwl_plot_all(gw_level_dv, gwl_data, parameter_cd = "62610", n_years = c(5, 20), POR_trend = TRUE, y_label = pcodes$parameter_name, plot_title = plot_title, add_trend = TRUE) gwl_plot_all(NULL, gwl_data, parameter_cd = "62610", plot_title = plot_title, y_label = pcodes$parameter_name) gwl_plot_all(NULL, gwl_data, parameter_cd = "62610", plot_title = plot_title, y_label = pcodes$parameter_name, add_trend = TRUE)site <- "USGS-263819081585801" # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete pcodes <- dataRetrieval::read_waterdata_parameter_codes( parameter_code = unique(gwl_data$parameter_code) ) gwl_plot_field(gwl_data, plot_title = "L2701_example", parameter_cd = "62610", flip = FALSE, y_label = pcodes$parameter_name[pcodes$parameter_code == "62610"]) gwl_plot_field(gwl_data, plot_title = "L2701_example", y_label = pcodes$parameter_name[pcodes$parameter_code == "62611"], parameter_cd = "62611", flip = FALSE) gwl_plot_field(gwl_data, plot_title = "L2701_example", y_label = pcodes$parameter_name[pcodes$parameter_code == "72019"], parameter_cd = "72019", flip = TRUE) site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily site_info <- dataRetrieval::read_waterdata_monitoring_location(monitoring_location_id = site) plot_title <- site_info$monitoring_location_name pcodes <- dataRetrieval::read_waterdata_parameter_codes(parameter_code = p_code_dv) gwl_plot_all(gw_level_dv, NULL, plot_title = plot_title, y_label = pcodes$parameter_name, flip = TRUE) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete gwl_plot_all(gw_level_dv, gwl_data, parameter_cd = "62610", plot_title = plot_title, y_label = pcodes$parameter_name, add_trend = FALSE, flip = FALSE) gwl_plot_all(gw_level_dv, gwl_data, parameter_cd = "62610", n_years = c(5, 20), POR_trend = TRUE, y_label = pcodes$parameter_name, plot_title = plot_title, add_trend = TRUE) gwl_plot_all(NULL, gwl_data, parameter_cd = "62610", plot_title = plot_title, y_label = pcodes$parameter_name) gwl_plot_all(NULL, gwl_data, parameter_cd = "62610", plot_title = plot_title, y_label = pcodes$parameter_name, add_trend = TRUE)
Example data from site 263819081585801 L-2701. Data is a named list of "Daily" for daily groundwater level at the site and "Discrete" for discrete groundwater level measurements from the site. Updated April 9, 2021.
head(L2701_example_data$Daily) head(L2701_example_data$Discrete) head(L2701_example_data$QW)head(L2701_example_data$Daily) head(L2701_example_data$Discrete) head(L2701_example_data$QW)
Find the last day of the month for a given date
last_day(date)last_day(date)
date |
a vector of dates |
the last day of the month that given dates fall in
date <- as.Date("2020-12-28") last_day(date) last_day("2020-02-15") last_day("2019-02-15") last_day(c("2020-12-28", "2020-02-15", "2019-02-15"))date <- as.Date("2020-12-28") last_day(date) last_day("2020-02-15") last_day("2019-02-15") last_day(c("2020-12-28", "2020-02-15", "2019-02-15"))
Map data used in composite hydrographs
map_hydro_data(x, site_info, num_years, parameter_cd = "72019")map_hydro_data(x, site_info, num_years, parameter_cd = "72019")
x |
aquifer data frame. Requires at least 3 columns. Two are required "site_no", "year", and "value". |
site_info |
data frame from |
num_years |
integer number of years required |
parameter_cd |
character, 5-digit parameter code, default is "72019". |
leaflet object
aquifer_data <- aquifer_data site_info <- site_info num_years <- 30 map_data <- map_hydro_data(aquifer_data, site_info, num_years) map_dataaquifer_data <- aquifer_data site_info <- site_info num_years <- 30 map_data <- map_hydro_data(aquifer_data, site_info, num_years) map_data
Find the middle of the month for a given date
mid_month(date)mid_month(date)
date |
a vector of dates |
the middle day of the month the given dates fall in
date <- as.Date("2020-12-28") mid_month(date) mid_month(c("2019-02-15", "2020-03-08", "2010-06-01"))date <- as.Date("2020-12-28") mid_month(date) mid_month(c("2019-02-15", "2020-03-08", "2010-06-01"))
This plot uses calculations from monthly_frequency_table. Daily, discrete,
or both types of data can be included.
monthly_frequency_plot( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), plot_title = "", subtitle = "U.S. Geological Survey", plot_range = c("Past year"), y_axis_label = "", flip = FALSE, percentile_colors = NA, include_edges = FALSE, median_point_size = 2.5, data_point_size = 2.5 )monthly_frequency_plot( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), plot_title = "", subtitle = "U.S. Geological Survey", plot_range = c("Past year"), y_axis_label = "", flip = FALSE, percentile_colors = NA, include_edges = FALSE, median_point_size = 2.5, data_point_size = 2.5 )
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
gwl_data |
data frame returned from |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
plot_title |
the title to use on the plot |
subtitle |
character. Sub-title for plot, default is "U.S. Geological Survey". |
plot_range |
the time frame to use for the plot. Use "Past year" (default) to see the last year of data, or "Calendar year" to use the current calendar year, beginning in January. Or specify two dates representing the start and end of the plot. If the first date is NA, it will start at the earliest record, if the second date is NA, it will end at the latest record. |
y_axis_label |
the label used for the y-axis of the plot. |
flip |
logical. If |
percentile_colors |
Optional argument to provide a vector of 5 colors used to fill the percentile bars in order from lowest percentile bin to the highest percentile bin. Default behavior (NA) is to use legacy plot colors. |
include_edges |
Optional argument to toggle on the "edge bins" min-5 and 95-max on the plot. Default is FALSE which does not plot those bins. |
median_point_size |
Optional argument to specify the size of the median point markers which are shown as black triangles on the plot. The default size is 2.5. |
data_point_size |
Optional argument to specify the size of the data point markers which are shown as red diamonds on the plot. The default size is 2.5. |
a ggplot with rectangles representing the historical monthly percentile, black triangles representing the historical monthly median, and red diamonds showing the last year of groundwater level measurements.
site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily label <- dataRetrieval::read_waterdata_parameter_codes(parameter_code = p_code_dv)$parameter_name monthly_frequency <- monthly_frequency_plot(gw_level_dv, gwl_data = NULL, plot_title = "L2701 Groundwater Level", y_axis_label = label, flip = FALSE) monthly_frequency # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete monthly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", plot_title = "L2701 Groundwater Level", y_axis_label = label, flip = FALSE) monthly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", plot_title = "L2701 Groundwater Level", y_axis_label = label, plot_range = c("2023-10-01", "2024-09-30"), flip = FALSE) monthly_frequency_flip <- monthly_frequency_plot(gw_level_dv, gwl_data, parameter_cd = "62610", y_axis_label = label, plot_title = "L2701 Groundwater Level", flip = TRUE) monthly_frequency_flip monthly_frequency_custom_colors <- monthly_frequency_plot( gw_level_dv, gwl_data, parameter_cd = "62610", y_axis_label = label, plot_title = "L2701 Groundwater Level", flip = TRUE, percentile_colors = c( "red", "yellow", "green", "blue", "orange" )) monthly_frequency_custom_colors monthly_frequency_edge_bins <- monthly_frequency_plot(gw_level_dv, gwl_data, parameter_cd = "62610", y_axis_label = label, plot_title = "L2701 Groundwater Level", flip = FALSE, include_edges = TRUE) monthly_frequency_edge_bins monthly_frequency_custom_point_sizes <- monthly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", plot_title = "L2701 Groundwater Level", y_axis_label = label, median_point_size = 0.5, data_point_size = 3) monthly_frequency_custom_point_sizessite <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily label <- dataRetrieval::read_waterdata_parameter_codes(parameter_code = p_code_dv)$parameter_name monthly_frequency <- monthly_frequency_plot(gw_level_dv, gwl_data = NULL, plot_title = "L2701 Groundwater Level", y_axis_label = label, flip = FALSE) monthly_frequency # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete monthly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", plot_title = "L2701 Groundwater Level", y_axis_label = label, flip = FALSE) monthly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", plot_title = "L2701 Groundwater Level", y_axis_label = label, plot_range = c("2023-10-01", "2024-09-30"), flip = FALSE) monthly_frequency_flip <- monthly_frequency_plot(gw_level_dv, gwl_data, parameter_cd = "62610", y_axis_label = label, plot_title = "L2701 Groundwater Level", flip = TRUE) monthly_frequency_flip monthly_frequency_custom_colors <- monthly_frequency_plot( gw_level_dv, gwl_data, parameter_cd = "62610", y_axis_label = label, plot_title = "L2701 Groundwater Level", flip = TRUE, percentile_colors = c( "red", "yellow", "green", "blue", "orange" )) monthly_frequency_custom_colors monthly_frequency_edge_bins <- monthly_frequency_plot(gw_level_dv, gwl_data, parameter_cd = "62610", y_axis_label = label, plot_title = "L2701 Groundwater Level", flip = FALSE, include_edges = TRUE) monthly_frequency_edge_bins monthly_frequency_custom_point_sizes <- monthly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", plot_title = "L2701 Groundwater Level", y_axis_label = label, median_point_size = 0.5, data_point_size = 3) monthly_frequency_custom_point_sizes
The table will accept daily, discrete, or a both types of data. The median of each
year/month is calculated. Then using that median, monthly stats are calculated.
Percentiles are calculated using the quantile function with "type=6".
monthly_frequency_table( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), flip = FALSE )monthly_frequency_table( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), flip = FALSE )
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
gwl_data |
data frame returned from |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
flip |
logical. If |
a data frame of monthly groundwater level statistics including the 5th, 10th, 25th, 75th, 90th, and 95th percentiles; the number of years of data; and the lowest monthly median and the highest monthly median.
site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily monthly_frequency <- monthly_frequency_table(gw_level_dv, NULL) head(monthly_frequency) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete monthly_frequency_combo <- monthly_frequency_table(gw_level_dv = gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610") head(monthly_frequency_combo) monthly_flip <- monthly_frequency_table(gw_level_dv, gwl_data, parameter_cd = "62610", flip = TRUE) head(monthly_flip)site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily monthly_frequency <- monthly_frequency_table(gw_level_dv, NULL) head(monthly_frequency) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete monthly_frequency_combo <- monthly_frequency_table(gw_level_dv = gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610") head(monthly_frequency_combo) monthly_flip <- monthly_frequency_table(gw_level_dv, gwl_data, parameter_cd = "62610", flip = TRUE) head(monthly_flip)
Take the mean of each month, filter if there's not at least 15 days, and create a new date that is the midpoint of each month.
monthly_mean(x, date_col = "time", value_col = "value")monthly_mean(x, date_col = "time", value_col = "value")
x |
data.frame |
date_col |
character name of date column |
value_col |
character name of value column |
# site <- "USGS-263819081585801" p_code_dv <- "62610" # statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd, # skipGeometry = TRUE) gw_level_dv <- L2701_example_data$Daily site_statistics <- monthly_frequency_table(gw_level_dv, NULL, parameter_cd = p_code_dv) gw_monthly <- monthly_mean(gw_level_dv)# site <- "USGS-263819081585801" p_code_dv <- "62610" # statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd, # skipGeometry = TRUE) gw_level_dv <- L2701_example_data$Daily site_statistics <- monthly_frequency_table(gw_level_dv, NULL, parameter_cd = p_code_dv) gw_monthly <- monthly_mean(gw_level_dv)
National aquifer data
Local aquifer data codes
markerTable raw data
data frame with columns Country, State, nat_aqfr_cd, long_name, and other_cd
data frame with columns long_name, nat_aqfr_cd, state_indexes, and states
data frame with aqfr_cd, Aqfr_Name_prpr
data frame with columns Trend and MarkerDescription
data frame with columns trendType, trend, markerDescription, r_lwd
head(nat_aqfr_state) head(summary_aquifers) head(local_aqfr)head(nat_aqfr_state) head(summary_aquifers) head(local_aqfr)
Create normalized composite data
normalized_data(x, num_years, parameter_cd = "72019")normalized_data(x, num_years, parameter_cd = "72019")
x |
aquifer data |
num_years |
integer number of years required |
parameter_cd |
character, 5-digit parameter code, default is "72019". |
data frame with year, name, and value
aquifer_data <- aquifer_data num_years <- 30 norm_data <- normalized_data(aquifer_data, num_years, "72019")aquifer_data <- aquifer_data num_years <- 30 norm_data <- normalized_data(aquifer_data, num_years, "72019")
Create composite hydrograph plot
plot_composite_data( x, num_years = NA, parameter_cd = "72019", plot_title = "", subtitle = "U.S. Geological Survey" )plot_composite_data( x, num_years = NA, parameter_cd = "72019", plot_title = "", subtitle = "U.S. Geological Survey" )
x |
aquifer data frame. Requires at least 3 columns: "monitoring_location_id", "year", and "value". |
num_years |
integer number of years required. If |
parameter_cd |
character, 5-digit parameter code, default is "72019". |
plot_title |
character title included on plot. |
subtitle |
character. Sub-title for plot, default is "U.S. Geological Survey". |
ggplot2 object
aquifer_data <- aquifer_data comp_data <- plot_composite_data(aquifer_data, num_years = 30, parameter_cd = "72019", plot_title = "Calendar Year") comp_data # Do it on a water year: aquifer_data$cal_year <- aquifer_data$year aquifer_data$year <- aquifer_data$water_year plot_composite_data(aquifer_data, parameter_cd = "72019", num_years = 30, plot_title = "Water Year")aquifer_data <- aquifer_data comp_data <- plot_composite_data(aquifer_data, num_years = 30, parameter_cd = "72019", plot_title = "Calendar Year") comp_data # Do it on a water year: aquifer_data$cal_year <- aquifer_data$year aquifer_data$year <- aquifer_data$water_year plot_composite_data(aquifer_data, parameter_cd = "72019", num_years = 30, plot_title = "Water Year")
Create composite hydrograph plot
plot_normalized_data( x, num_years = NA, parameter_cd = "72019", plot_title = "", subtitle = "U.S. Geological Survey" )plot_normalized_data( x, num_years = NA, parameter_cd = "72019", plot_title = "", subtitle = "U.S. Geological Survey" )
x |
aquifer data frame. Requires at least 3 columns. Two are required "site_no", "year", and "value". |
num_years |
integer number of years required to the analysis. If |
parameter_cd |
character, 5-digit parameter code, default is "72019". |
plot_title |
character title of plot. |
subtitle |
character. Sub-title for plot, default is "U.S. Geological Survey". |
ggplot2 object
aquifer_data <- aquifer_data norm_data <- plot_normalized_data(aquifer_data, parameter_cd = "72019", num_years = 30) norm_data aquifer_data$cal_year <- aquifer_data$year aquifer_data$year <- aquifer_data$water_year plot_normalized_data(aquifer_data, parameter_cd = "72019", num_years = 30)aquifer_data <- aquifer_data norm_data <- plot_normalized_data(aquifer_data, parameter_cd = "72019", num_years = 30) norm_data aquifer_data$cal_year <- aquifer_data$year aquifer_data$year <- aquifer_data$water_year plot_normalized_data(aquifer_data, parameter_cd = "72019", num_years = 30)
Functions to create the individual chloride, specific conductance, and combination plots and tables for a single site.
Sc_Cl_plot(qw_data, plot_title, subtitle = "U.S. Geological Survey") Sc_Cl_table(qw_data) qw_plot( qw_data, plot_title, y_label = NA, CharacteristicName = "Chloride", start_date = NA, end_date = NA, subtitle = "U.S. Geological Survey" ) qw_summary(qw_data, CharacteristicName, norm_range = NA)Sc_Cl_plot(qw_data, plot_title, subtitle = "U.S. Geological Survey") Sc_Cl_table(qw_data) qw_plot( qw_data, plot_title, y_label = NA, CharacteristicName = "Chloride", start_date = NA, end_date = NA, subtitle = "U.S. Geological Survey" ) qw_summary(qw_data, CharacteristicName, norm_range = NA)
qw_data |
data frame returned from |
plot_title |
character title for plot |
subtitle |
character. Sub-title for plot, default is "U.S. Geological Survey". |
y_label |
character label for y axis. If left as NA, the function will attempt to use the "variableInfo" attribute of qw_data. This is attached to dataRetrieval output. |
CharacteristicName |
character CharacteristicName to filter to. |
start_date |
Date to start plot. If |
end_date |
Date to end plot. If |
norm_range |
a numerical range to potentially group the data. If NA, no grouping is shown. |
# site <- "USGS-263819081585801" # parameterCd <- c("00095","90095","00940","99220") # site_data <- dataRetrieval::readWQPqw(site, # parameterCd) # Using package example data: qw_data <- L2701_example_data$QW plot_title <- paste("USGS-263819081585801", ": Specific Conductance vs Chloride") Sc_Cl_plot(qw_data, plot_title) sc_cl <- Sc_Cl_table(qw_data) plot_title <- paste("USGS-263819081585801", ": Specific Conductance vs Chloride") qw_plot(qw_data, plot_title, CharacteristicName = "Chloride") qw_plot(qw_data, plot_title, CharacteristicName = "Specific conductance") qw_plot(qw_data, plot_title, CharacteristicName = "Specific conductance", start_date = "1990-01-01") site <- "USGS-01491000" qw_data_phos <- dataRetrieval::readWQPqw(site, "Orthophosphate") qw_plot(qw_data_phos , CharacteristicName = "Orthophosphate", plot_title = "Choptank: Orthophosphate") qw_summary(qw_data, CharacteristicName = "Chloride", norm_range = c(230, 860)) qw_summary(qw_data, CharacteristicName = "Specific conductance", norm_range = NA)# site <- "USGS-263819081585801" # parameterCd <- c("00095","90095","00940","99220") # site_data <- dataRetrieval::readWQPqw(site, # parameterCd) # Using package example data: qw_data <- L2701_example_data$QW plot_title <- paste("USGS-263819081585801", ": Specific Conductance vs Chloride") Sc_Cl_plot(qw_data, plot_title) sc_cl <- Sc_Cl_table(qw_data) plot_title <- paste("USGS-263819081585801", ": Specific Conductance vs Chloride") qw_plot(qw_data, plot_title, CharacteristicName = "Chloride") qw_plot(qw_data, plot_title, CharacteristicName = "Specific conductance") qw_plot(qw_data, plot_title, CharacteristicName = "Specific conductance", start_date = "1990-01-01") site <- "USGS-01491000" qw_data_phos <- dataRetrieval::readWQPqw(site, "Orthophosphate") qw_plot(qw_data_phos , CharacteristicName = "Orthophosphate", plot_title = "Choptank: Orthophosphate") qw_summary(qw_data, CharacteristicName = "Chloride", norm_range = c(230, 860)) qw_summary(qw_data, CharacteristicName = "Specific conductance", norm_range = NA)
Get summaries of data by site. Requires a column site_no, and will take the summaries
site_data_summary(x, value_col = "value", site_col = "monitoring_location_id")site_data_summary(x, value_col = "value", site_col = "monitoring_location_id")
x |
data frame |
value_col |
name of value column. The default is |
site_col |
name of site column. This is the column we are grouping by. |
data frame with 10 columns
aquifer_data <- aquifer_data aquifer_data <- aquifer_data[aquifer_data$parameter_code == "72019", ] summary_info <- site_data_summary(aquifer_data)aquifer_data <- aquifer_data aquifer_data <- aquifer_data[aquifer_data$parameter_code == "72019", ] summary_info <- site_data_summary(aquifer_data)
Get station summary information
site_summary(siteID, markdown = FALSE)site_summary(siteID, markdown = FALSE)
siteID |
character |
markdown |
logical. Use markdown formating or console-friendly. |
siteID <- "USGS-263819081585801" site_metadata <- site_summary(siteID)siteID <- "USGS-263819081585801" site_metadata <- site_summary(siteID)
The table will accept daily, discrete, or a both types of data. The median of each
year/month is calculated. Then using that median, monthly stats are calculated.
Percentiles are calculated using the quantile function with "type=6".
stats_by_interval( interval, gw_level_dv, gwl_data, parameter_cd = NA, date_col = NA, value_col = NA, approved_col = NA, flip = FALSE )stats_by_interval( interval, gw_level_dv, gwl_data, parameter_cd = NA, date_col = NA, value_col = NA, approved_col = NA, flip = FALSE )
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
gwl_data |
data frame returned from |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
flip |
logical. If |
site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily monthly_frequency <- stats_by_interval("month", gw_level_dv, NULL) head(monthly_frequency) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete gwl_data <- gwl_data[gwl_data$parameter_code == p_code_dv, ] monthly_frequency2 <- stats_by_interval("month", gw_level_dv, gwl_data) annual_frequency2 <- stats_by_interval("year", gw_level_dv, gwl_data) week_frequency2 <- stats_by_interval("week", gw_level_dv, gwl_data)site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily monthly_frequency <- stats_by_interval("month", gw_level_dv, NULL) head(monthly_frequency) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete gwl_data <- gwl_data[gwl_data$parameter_code == p_code_dv, ] monthly_frequency2 <- stats_by_interval("month", gw_level_dv, gwl_data) annual_frequency2 <- stats_by_interval("year", gw_level_dv, gwl_data) week_frequency2 <- stats_by_interval("week", gw_level_dv, gwl_data)
Themes and other useful graphing utilities for the HASP package
theme_gwl(base_family = "", ...) hasp_framework( x_label, y_label, plot_title, include_y_scale = FALSE, zero_on_top = TRUE, subtitle = "U.S. Geological Survey" )theme_gwl(base_family = "", ...) hasp_framework( x_label, y_label, plot_title, include_y_scale = FALSE, zero_on_top = TRUE, subtitle = "U.S. Geological Survey" )
base_family |
character base font family |
... |
additional arguments |
x_label |
character. Label for x-axis. |
y_label |
character. Label for y-axis. |
plot_title |
character. Title for plot. |
include_y_scale |
logical. If |
zero_on_top |
logical. If zero_on_top is |
subtitle |
character. Sub-title for plot, default is "U.S. Geological Survey". |
ggplot2::ggplot() + theme_gwl() x_label <- "Date" y_label <- "Level" plot_title <- "Super Site" ggplot2::ggplot() + hasp_framework(x_label, y_label, plot_title)ggplot2::ggplot() + theme_gwl() x_label <- "Date" y_label <- "Level" plot_title <- "Super Site" ggplot2::ggplot() + hasp_framework(x_label, y_label, plot_title)
Function creates the cloride over time plot with trends.
trend_plot( qw_data, plot_title, y_label = NA, n_years = 10, POR_trend = TRUE, CharacteristicName = c("Chloride"), norm_range = c(230, 860), subtitle = "U.S. Geological Survey", include_table = TRUE )trend_plot( qw_data, plot_title, y_label = NA, n_years = 10, POR_trend = TRUE, CharacteristicName = c("Chloride"), norm_range = c(230, 860), subtitle = "U.S. Geological Survey", include_table = TRUE )
qw_data |
data frame returned from |
plot_title |
character title for plot |
y_label |
character label for y axis. If left as NA, the function will attempt to use the "variableInfo" attribute of qw_data. This is attached to dataRetrieval output. |
n_years |
integer. This is the number of years to calculate the trend on. Default is 10. This can be a vector of years. |
POR_trend |
a logical indicating whether to include a trend test
for the full period of record. Default is |
CharacteristicName |
character CharacteristicName to plot |
norm_range |
a numerical range to potentially group the data. If NA, no grouping is shown. |
subtitle |
character. Sub-title for plot, default is "U.S. Geological Survey". |
include_table |
logical whether or not to include the trend table in the upper left corner. |
# site <- "USGS-263819081585801" # parameterCd <- c("00095","90095","00940","99220") # site_data <- dataRetrieval::readWQPqw(site, # parameterCd) # Using package example data: qw_data <- L2701_example_data$QW plot_title <- paste(attr(qw_data, "siteInfo")[["station_nm"]], ": Chloride") trend_plot(qw_data, plot_title)# site <- "USGS-263819081585801" # parameterCd <- c("00095","90095","00940","99220") # site_data <- dataRetrieval::readWQPqw(site, # parameterCd) # Using package example data: qw_data <- L2701_example_data$QW plot_title <- paste(attr(qw_data, "siteInfo")[["station_nm"]], ": Chloride") trend_plot(qw_data, plot_title)
Test for period of record and user-specified ranges. The default trends are calculated for 10 year and the full period of record.
trend_test( gw_level_dv, gwl_data, n_years = 10, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), pctComplete = 0.5, days_required_per_month = 14, POR_trend = TRUE )trend_test( gw_level_dv, gwl_data, n_years = 10, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), pctComplete = 0.5, days_required_per_month = 14, POR_trend = TRUE )
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
gwl_data |
data frame returned from |
n_years |
integer. This is the number of years to calculate the trend on. Default is 10. This can be a vector of years. |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
pctComplete |
number percentage complete. This is a fraction that represents the amount of data that must be included overall in order to calculate a trend. The default is 0.5, which means if gaps in the data span more than 50 total record, a trend will not be calculated. |
days_required_per_month |
integer. Number of days required per month to include in the trend test. Default is 14. |
POR_trend |
a logical indicating whether to include a trend test
for the full period of record. Default is |
For data that is at least on a daily interval, the rkt function is used. For periodic data, the kendallTrendTest is used.
a data frame of test results from 5 and 20 year Kendall Seasonal Trend test
site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # Using package example data: # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily trend_test(gw_level_dv, gwl_data, parameter_cd = "62610") trend_test(gw_level_dv, gwl_data, POR_trend = FALSE, parameter_cd = "62610") trend_test(gw_level_dv, gwl_data, parameter_cd = "62610", n_years = 5) trend_test(gw_level_dv, gwl_data, parameter_cd = "62610", n_years = c(5, 10, 20)) # Only periodic data: trend_test(NULL, gwl_data, parameter_cd = "62610")site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # Using package example data: # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily trend_test(gw_level_dv, gwl_data, parameter_cd = "62610") trend_test(gw_level_dv, gwl_data, POR_trend = FALSE, parameter_cd = "62610") trend_test(gw_level_dv, gwl_data, parameter_cd = "62610", n_years = 5) trend_test(gw_level_dv, gwl_data, parameter_cd = "62610", n_years = c(5, 10, 20)) # Only periodic data: trend_test(NULL, gwl_data, parameter_cd = "62610")
This function is a little more robust than calcWaterYear
water_year(x)water_year(x)
x |
character vector |
x <- c("2010-01-01", "1994-02", "1980", "2009-11-01") water_year(x)x <- c("2010-01-01", "1994-02", "1980", "2009-11-01") water_year(x)
Weekly statistics are calculated using the weekly_frequency_table function.
Daily, discrete, or both types of data can be used.
weekly_frequency_plot( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), plot_range = "Past year", plot_title = "", subtitle = "U.S. Geological Survey", y_axis_label = "", flip = FALSE, percentile_colors = NA )weekly_frequency_plot( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), plot_range = "Past year", plot_title = "", subtitle = "U.S. Geological Survey", y_axis_label = "", flip = FALSE, percentile_colors = NA )
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
gwl_data |
data frame returned from |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
plot_range |
the time frame to use for the plot. Use "Past year" (default) to see the last year of data, or "Calendar year" to use the current calendar year, beginning in January. Or specify two dates representing the start and end of the plot. If the first date is NA, it will start at the earliest record, if the second date is NA, it will end at the latest record. |
plot_title |
the title to use on the plot |
subtitle |
character. Sub-title for plot, default is "U.S. Geological Survey". |
y_axis_label |
the label used for the y-axis of the plot. |
flip |
logical. If |
percentile_colors |
Optional argument to provide a vector of 5 colors used to fill the percentile bars in order from lowest percentile bin to the highest percentile bin. Default behavior (NA) is to use legacy plot colors. |
a ggplot object with rectangles representing the historical weekly percentiles, and points representing the historical median and daily values
site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily weekly_frequency_plot(gw_level_dv, gwl_data = NULL) weekly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", plot_range = c("2023-10-01", "2024-09-30")) weekly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610") weekly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", flip = TRUE)site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily weekly_frequency_plot(gw_level_dv, gwl_data = NULL) weekly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", plot_range = c("2023-10-01", "2024-09-30")) weekly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610") weekly_frequency_plot(gw_level_dv, gwl_data = gwl_data, parameter_cd = "62610", flip = TRUE)
The weekly frequency analysis is based on daily, discrete, or both types of data. The median of each year/week combo is calculated, then overall weekly statistics are calculated off of that median.
weekly_frequency_table( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), flip = FALSE )weekly_frequency_table( gw_level_dv, gwl_data, parameter_cd = NA, date_col = c("time", "time"), value_col = c("value", "value"), approved_col = c("approval_status", "approval_status"), flip = FALSE )
gw_level_dv |
data frame, daily groundwater level data. Often obtained
from |
gwl_data |
data frame returned from |
parameter_cd |
Can be used to filter data if the data frame has a
"parameter_code" column. The default is |
date_col |
the name of the time columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
value_col |
the name of the value columns. The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
approved_col |
the name of the column to get provisional/approved status.
The first value is associated
with the gw_level_dv input, and the second value is associated with the gwl_data
input. The default is |
flip |
logical. If |
a data frame of weekly frequency analysis
site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily weekly_frequency <- weekly_frequency_table(gw_level_dv, NULL) head(weekly_frequency) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete weekly_frequency <- weekly_frequency_table(gw_level_dv, gwl_data, parameter_cd = "62610") head(weekly_frequency) weekly_flip <- weekly_frequency_table(gw_level_dv, gwl_data, parameter_cd = "62610", flip = TRUE) head(weekly_flip)site <- "USGS-263819081585801" p_code_dv <- "62610" statCd <- "00001" # gw_level_dv <- dataRetrieval::read_waterdata_daily(monitoring_location_id = site, # parameter_code = p_code_dv, # statistic_id = statCd) gw_level_dv <- L2701_example_data$Daily weekly_frequency <- weekly_frequency_table(gw_level_dv, NULL) head(weekly_frequency) # gwl_data <- dataRetrieval::read_waterdata_field_measurements(monitoring_location_id = site) gwl_data <- L2701_example_data$Discrete weekly_frequency <- weekly_frequency_table(gw_level_dv, gwl_data, parameter_cd = "62610") head(weekly_frequency) weekly_flip <- weekly_frequency_table(gw_level_dv, gwl_data, parameter_cd = "62610", flip = TRUE) head(weekly_flip)