knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "tools/readme/", message = FALSE )
An R r emo::ji("package")
to download open water quality data from Environment and Climate Change Canada's National Long-term Water Quality Monitoring Data.
This package is designed to get Canadian Water Quality Monitoring data into R quickly and easily. You can get data from a single monitoring station, multiple stations, or from an entire basin.
remotes::install_github("bcgov/canwqdata")
First load the package:
library(canwqdata)
The first thing you will probably want to do is get a list of the available sites and associated metadata:
sites <- wq_sites() sites
Then get some data from a particular station:
AL07AA0015
is a site in Alberta called r tools::toTitleCase(tolower(sites$SITE_NAME[sites$SITE_NO == "AL07AA0015"]))
athabasca_falls <- wq_site_data("AL07AA0015") athabasca_falls
We can also get data from more than one station:
wq_site_data(c("YT09FC0002", "SA05JM0014"))
Or an entire basin:
The basins are in the PEARSEDA
column of the data.frame returned by wq_sites()
:
basins <- sort(unique(sites$PEARSEDA)) basins fraser <- wq_basin_data("FRASER-LOWER MAINLAND")
Do some quick summary stats of the fraser dataset:
library(dplyr) fraser %>% group_by(SITE_NO) %>% summarise(first_date = min(DATE_TIME_HEURE), latest_date = max(DATE_TIME_HEURE), n_params = length(unique(VARIABLE)), total_samples = n())
We can also look at metadata that helps us understand what is in the different columns.
wq_params()
returns a list of water quality parameters (variables), and related data - units, methods, codes, etc:
params <- wq_params() glimpse(params) # wq_param_desc shows the column headings (in all other tables) and what they mean wq_data_desc() %>% glimpse()
Let's look at Total Nitrogen in the Fraser basin:
fraser_n_total <- fraser %>% filter(VARIABLE == "NITROGEN TOTAL")
Now lets do some plotting - plot Total Nitrogen over time at all the sites, (plot it on a log scale so that they all fit)
library(ggplot2) ggplot(fraser_n_total, aes(x = DATE_TIME_HEURE, y = VALUE_VALEUR)) + geom_point(size = 0.4, alpha = 0.4, colour = "purple") + facet_wrap(~ SITE_NO) + scale_y_log10()
It's also possible to download data from an entire province:
bc_sites <- sites %>% filter(PROV_TERR == "BC") %>% pull(SITE_NO) all_bc_data <- wq_site_data(bc_sites) glimpse(all_bc_data)
Under development, but ready for use and testing.
To report bugs/issues/feature requests, please file an issue.
If you would like to contribute to the package, please see our CONTRIBUTING guidelines.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Copyright 2018 Province of British Columbia Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This repository is maintained by Environmental Reporting BC. Click here for a complete list of our repositories on GitHub.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.