Package 'wqindex'

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-09-17 19:14:20 UTC
Source: https://github.com/poissonconsulting/wqindex

Help Index


Calculate Water Quality Index (WQI)

Description

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.

Usage

calc_wqi(x, by = NULL, messages = getOption("wqbc.messages", default =
  TRUE))

Arguments

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.

Details

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.

See Also

wqbc::calc_limits()

Examples

data(ccme)
calc_wqi(ccme, messages = TRUE)
calc_wqi(ccme, by = "Date", messages = TRUE)

Categorize Water Quality Indices

Description

Categorizes numbers between 1 and 100 into the categories defined in the CCME Water Quality Index 1.0 User's Manual.

Usage

categorize_wqi(x)

Arguments

x

A numeric vector of the WQI values to categorize.

Examples

categorize_wqi(seq(1,100,by = 5))

CCME Water Quality Index User's Manual Example Data

Description

The Canadian Council of Ministers of the Environment (CCME) Water Quality Index 1.0 User's Manual example dataset in tidy format.

Usage

ccme

Format

A data frame with 120 rows and 7 columns:

Date

The date of the reading.

Variable

The name of the variable.

Value

The value of the reading.

DetectionLimit

The detection limit.

LowerLimit

The minimum permitted value.

UpperLimit

The maximum permitted value.

Units

The units of the value, detection limit and lower and upper limits.

Examples

demo(ccme)

Dummy Water Quality Data

Description

A dummy data set to illustrate various data cleaning functions.

Usage

dummy

Format

A data frame with 4 columns:

Date

The date of the reading.

Variable

The name of the variable.

Value

The value of the reading.

Units

The units of the value.

Examples

demo(dummy)

Error

Description

Throws an error without the call as part of the error message.

Usage

error(...)

Arguments

...

zero or more objects which can be coerced to character (and which are pasted together with no separator) or a single condition object.

See Also

base::stop


Get Category Colours

Description

Returns a named vector of the WQI category colours used for plotting.

Usage

get_category_colours()

Plot Map

Description

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.

Usage

plot_map(data, x = "Long", y = "Lat", size = 3, shape = 21,
  fill = 10, keep = NULL, input_proj = NULL)

Arguments

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 ("+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs").

See Also

plot_map_wqis

Examples

library(ggplot2)
library(sp)
library(rgdal)
library(wqbc)

data(fraser)
plot_map(fraser)

## Not run: 
 demo(fraser)

## End(Not run)

Plot Map of Water Quality Index Categories.

Description

Creates a ggplot2 object with a polygon of British Columbia with the Water Quality Index categories indicated by the fill colour of points.

Usage

plot_map_wqis(data, x = "Long", y = "Lat", size = 3, shape = 21,
  keep = NULL, input_proj = NULL)

Arguments

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 ("+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs").

See Also

plot_wqis and plot_map

Examples

## Not run: 
 demo(fraser)

## End(Not run)

Plot Time Series Data

Description

If by = NULL plot_timeseries returns a ggplot object. Otherwise it returns a list of ggplot objects.

Usage

plot_timeseries(data, by = NULL, y0 = TRUE, size = 1,
  messages = getOption("wqbc.messages", default = TRUE))

Arguments

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.

Examples

plot_timeseries(ccme[ccme$Variable == "As",])
plot_timeseries(ccme, by = "Variable")

Plot Water Quality Indices

Description

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.

Usage

plot_wqis(data, x = "Tests", size = 3, shape = 21)

Arguments

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.

See Also

plot_map_wqis


Water Quality Index Calculation

Description

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.

See Also

calc_wqi and plot_wqis

Examples

## Not run: 
 demo(ccme)
 demo(dummy)
 demo(fraser)

## End(Not run)