Title: | Water Quality Index Calculation for British Columbia |
---|---|
Description: | Calculates water quality thresholds and water quality indices and plots water quality indices spatially and temporally for British Columbia. |
Authors: | Joe Thorley [aut, ctr] (Primary author), Colin Millar [aut, ctr], Andy Teucher [aut, cre], Wendy Wang [ctb, ctr], Stephanie Hazlitt [ctb], Robyn Irvine [ctb, ctr], Province of British Columbia [cph] |
Maintainer: | Andy Teucher <[email protected]> |
License: | Apache License (== 2.0) | file LICENSE |
Version: | 0.3.1.9001 |
Built: | 2024-10-17 06:17:14 UTC |
Source: | https://github.com/poissonconsulting/wqindex |
Calculates a water quality index for a series of variables, values with upper limits and optionally lower limits using the method detailed in the CCME Water Quality Index 1.0 User's Manual.
calc_wqi(x, by = NULL, messages = getOption("wqbc.messages", default = TRUE))
calc_wqi(x, by = NULL, messages = getOption("wqbc.messages", default = TRUE))
x |
A data.frame to calculate the WQI for. |
by |
An optional character vector of the columns in x to calculate the WQI by. |
messages |
A flag indicating whether to print messages. |
The upper limits can be generated using the wqbc::calc_limits()
function
or can be provided by the user. If values are zero and detection limits are provided
then the values are set to be the detection limits. This is important when
the variable has lower limits because otherwise the excursion will be infinity
and it will not be possible to calculate the WQI. In this case calc_wqi
throws an informative error. Finally it is important to note that in order
for the WQI to be calculated the data set must include four variables each
with non-missing values on at least four separate days. In addition
to calculating the WQI the function also generates
95
intervals are generated by first spreading the data into wide format where each
row represents one date and then resampling the rows with replacement to
generate 1,000 replicates. The confidence intervals are the 2.5
percentiles of the replicate WQIs.
data(ccme) calc_wqi(ccme, messages = TRUE) calc_wqi(ccme, by = "Date", messages = TRUE)
data(ccme) calc_wqi(ccme, messages = TRUE) calc_wqi(ccme, by = "Date", messages = TRUE)
Categorizes numbers between 1 and 100 into the categories defined in the CCME Water Quality Index 1.0 User's Manual.
categorize_wqi(x)
categorize_wqi(x)
x |
A numeric vector of the WQI values to categorize. |
categorize_wqi(seq(1,100,by = 5))
categorize_wqi(seq(1,100,by = 5))
The Canadian Council of Ministers of the Environment (CCME) Water Quality Index 1.0 User's Manual example dataset in tidy format.
ccme
ccme
A data frame with 120 rows and 7 columns:
The date of the reading.
The name of the variable.
The value of the reading.
The detection limit.
The minimum permitted value.
The maximum permitted value.
The units of the value, detection limit and lower and upper limits.
demo(ccme)
demo(ccme)
A dummy data set to illustrate various data cleaning functions.
dummy
dummy
A data frame with 4 columns:
The date of the reading.
The name of the variable.
The value of the reading.
The units of the value.
demo(dummy)
demo(dummy)
Throws an error without the call as part of the error message.
error(...)
error(...)
... |
zero or more objects which can be coerced to character (and which are pasted together with no separator) or a single condition object. |
base::stop
Returns a named vector of the WQI category colours used for plotting.
get_category_colours()
get_category_colours()
Creates a ggplot2 object with a polygon of British Columbia. If any columns are required for additional layers in the plot or facetting then they should be specified in the keep argument.
plot_map(data, x = "Long", y = "Lat", size = 3, shape = 21, fill = 10, keep = NULL, input_proj = NULL)
plot_map(data, x = "Long", y = "Lat", size = 3, shape = 21, fill = 10, keep = NULL, input_proj = NULL)
data |
A data.frame with spatial information to map. |
x |
A string of the column in data to plot on the x axis. |
y |
A string of the column in data to plot on the y axis. |
size |
A number of the point size or a string of the column in data to represent by the size of points. |
shape |
An integer of the point shape (permitted values are 21 to 25) or a string of the column in data to represent by the shape of points. |
fill |
An integer of the point fill colour or a string of the column in data to represent by the fill colour of points. |
keep |
An optional character vector indicating which columns in addition to x and y to keep before dropping duplicated rows to avoid overplotting. |
input_proj |
An optional valid proj4string. Defaults to
( |
library(ggplot2) library(sp) library(rgdal) library(wqbc) data(fraser) plot_map(fraser) ## Not run: demo(fraser) ## End(Not run)
library(ggplot2) library(sp) library(rgdal) library(wqbc) data(fraser) plot_map(fraser) ## Not run: demo(fraser) ## End(Not run)
Creates a ggplot2 object with a polygon of British Columbia with the Water Quality Index categories indicated by the fill colour of points.
plot_map_wqis(data, x = "Long", y = "Lat", size = 3, shape = 21, keep = NULL, input_proj = NULL)
plot_map_wqis(data, x = "Long", y = "Lat", size = 3, shape = 21, keep = NULL, input_proj = NULL)
data |
A data.frame of WQI values to plot. |
x |
A string of the column in data to plot on the x axis. |
y |
A string of the column in data to plot on the y axis. |
size |
A number of the point size or string of the column in data to represent by the size of points. |
shape |
An integer of the point shape (permitted values are 21 to 25) or string of the column in data to represent by the shape of points. |
keep |
An optional character vector indicating which columns in addition to x and y to keep before dropping duplicated rows to avoid overplotting. |
input_proj |
An optional valid proj4string. Defaults to
( |
## Not run: demo(fraser) ## End(Not run)
## Not run: demo(fraser) ## End(Not run)
If by = NULL
plot_timeseries returns a ggplot object.
Otherwise it returns a list of ggplot objects.
plot_timeseries(data, by = NULL, y0 = TRUE, size = 1, messages = getOption("wqbc.messages", default = TRUE))
plot_timeseries(data, by = NULL, y0 = TRUE, size = 1, messages = getOption("wqbc.messages", default = TRUE))
data |
A data frame of the data to plot. |
by |
A character vector of the columns to plot the time series by. |
y0 |
A flag indicating whether to expand the y-axis limits to include 0. |
size |
A number of the point size. |
messages |
A flag indicating whether to print messages. |
plot_timeseries(ccme[ccme$Variable == "As",]) plot_timeseries(ccme, by = "Variable")
plot_timeseries(ccme[ccme$Variable == "As",]) plot_timeseries(ccme, by = "Variable")
Creates a ggplot2 scatterplot object with the y-limits expanded to include 0 and 100. Water Quality Index categories are indicated by the fill colour of points.
plot_wqis(data, x = "Tests", size = 3, shape = 21)
plot_wqis(data, x = "Tests", size = 3, shape = 21)
data |
A data.frame of WQI values to plot. |
x |
A string of the column in data to plot on the x axis. |
size |
A number of the point size or string of the column in data to represent by the size of points. |
shape |
An integer of the point shape (permitted values are 21 to 25) or string of the column in data to represent by the shape of points. |
The wqindex package calculates water quality thresholds and indices for
freshwater life in British Columbia. To the best of the
package creator's knowledge the limits correspond to the
approved Provincial thresholds on the date of
release but wqbc comes with ABSOLUTELY NO WARRANTY. For further
information on the use of the wqbc package please type
vignette("wqindex")
at the R console.
## Not run: demo(ccme) demo(dummy) demo(fraser) ## End(Not run)
## Not run: demo(ccme) demo(dummy) demo(fraser) ## End(Not run)