
Plot monthly frequency plot
monthly_frequency_plot.RdThis plot uses calculations from monthly_frequency_table. Daily, discrete,
or both types of data can be included.
Usage
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
)Arguments
- gw_level_dv
data frame, daily groundwater level data. Often obtained from
read_waterdata_daily. UseNULLfor no daily data.- gwl_data
data frame returned from
read_waterdata_field_measurements, or data frame with a date, value, and approval columns. UseNULLfor no discrete data.- parameter_cd
Can be used to filter data if the data frame has a "parameter_code" column. The default is
NA, which will not do any filtering. If the gwl_data and gw_level_dv need different parameter code filtering, use a vector of 2 parameter codes. The first one will filter the gw_level_dv data frame, the second will filter the gwl_data data frame.- 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
c("time", "time").- 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
c("value", "value").- 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
c("approval_status", "approval_status"). It is expected that these columns will have only "Approved" or "Provisional".- 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
TRUE, flips labels so that the lower numbers are in the higher percentages. Default isTRUE.- 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.
Value
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.
Examples
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
label <- dataRetrieval::read_waterdata_parameter_codes(parameter_code = p_code_dv)$parameter_name
#> Requesting:
#> https://api.waterdata.usgs.gov/ogcapi/v0/collections/parameter-codes/items?f=json&lang=en-US&skipGeometry=TRUE&limit=10000&id=62610
#> Remaining requests this hour:527
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,
# skipGeometry = TRUE)
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