The IDEMwater
R
package is a collection of functions for IDEM’s Office of Water Quality. Use the devtools package to install:
if(!require("devtools")) install.packages("devtools")
library("devtools")
install_github("InDEM/IDEMwater")
library(IDEMwater)
To use the precipPlot()
function, you need the precipitation and sampled data in a wide data frame. For an example, we use data from the IDEMdata
package:
if(!require("devtools")) install.packages("devtools")
library("devtools")
install_github("InDEM/IDEMdata")
library(IDEMdata)
data(wide_precip)
head(wide.precip.df, 20)
## date station activity waterbody utm_e utm_n
## 1 2013-04-01 <NA> <NA> <NA> NA NA
## 2 2013-04-02 <NA> <NA> <NA> NA NA
## 3 2013-04-03 <NA> <NA> <NA> NA NA
## 4 2013-04-04 <NA> <NA> <NA> NA NA
## 5 2013-04-05 <NA> <NA> <NA> NA NA
## 6 2013-04-06 <NA> <NA> <NA> NA NA
## 7 2013-04-07 <NA> <NA> <NA> NA NA
## 8 2013-04-08 LMG-05-0009 AB11831 Duck Creek 478813 4598169
## 9 2013-04-08 LMG-05-0004 AB11819 Willow Creek 484237 4601489
## 10 2013-04-08 LMG030-0008 AB11830 Deep River 478610 4598226
## 11 2013-04-08 LMG-05-0032 AB11799 Duck Creek 482415 4596111
## 12 2013-04-08 LMG-05-0002 AB11797 Burns Ditch 481607 4604682
## 13 2013-04-08 LMG-05-0008 AB11829 Tributary of Deep River 480291 4600822
## 14 2013-04-08 LMG-05-0006 AB11827 Deep River 475456 4601587
## 15 2013-04-08 LMG-05-0003 AB11808 Willow Creek 482962 4604086
## 16 2013-04-08 LMG-05-0007 AB11828 Deep River 475754 4601280
## 17 2013-04-08 LMG-05-0010 AB11798 Tributary of Duck Creek 479989 4596688
## 18 2013-04-08 LMG-05-0033 AB11801 Sprout Ditch 475992 4593522
## 19 2013-04-08 LMG-05-0011 AB11800 Deep River 476136 4595624
## 20 2013-04-09 LMG-05-0015 AB11806 Deep River 476810 4588423
There are 27 columns of sampled data, and one precipitation column:
colnames(wide.precip.df)
## [1] "date" "station"
## [3] "activity" "waterbody"
## [5] "utm_e" "utm_n"
## [7] "county" "sat"
## [9] "air_temp" "alkalinity"
## [11] "chloride" "cod"
## [13] "coliforms" "do"
## [15] "e_coli" "flow"
## [17] "hardness" "nitrogen_ammonia"
## [19] "nitrogen_nitratenitrite" "ph"
## [21] "phosphorus_total" "sky_conditions"
## [23] "solids_suspended_total" "solids_total"
## [25] "solids_total_dissolved" "specific_conductance"
## [27] "sulfate" "temperature"
## [29] "tkn" "toc"
## [31] "turbidity" "turbidity_hach"
## [33] "wind_direction" "wind_strength"
## [35] "jday" "precipitation"
The precipPlot()
function takes a data frame like wide.precip.df
, as well as vectors that specify which samples and which monitors to plot. Other options can be supplied as vectors as well. These options need to have the same order as the sample vector. See ?precipPlot
.
The best way to create input vectors for the function is to make a table. Let’s say I want plots for nitrogen and e. coli for sites GMW-04-0018 and GMW-05-0006. I want those four combinations, so if I leave the parameter ‘all.combos’ as TRUE, then the function will create plots for each combination of those two samples and those two monitors. Below is a data frame that I’ll use for the function inputs:
input.df <- data.frame(site.ids = c("LMG-05-0009", "LMG-05-0004"),
parameters = c("e_coli", "nitrogen_ammonia"),
names = c("E. coli", "Nitrogen Ammonia"),
standards = c(1000, 0.05), log = c(TRUE, FALSE))
input.df
## site.ids parameters names standards log
## 1 LMG-05-0009 e_coli E. coli 1e+03 TRUE
## 2 LMG-05-0004 nitrogen_ammonia Nitrogen Ammonia 5e-02 FALSE
And here’s the function call that will create the four plots (but only the first plot is shown below):
precipPlot(data = wide.precip.df, sites = input.df$site.ids,
substances = input.df$parameters, substance.names = input.df$names,
standards = input.df$standards, log = input.df$log, save = FALSE)
Now lets say that I only want e coli for site GMW-04-0018 and both e coli and nitrogen for GMW-05-0006. I create a data frame so that the rows contain the appropriate information for each plot I want to make, including titles, and I set all.combos = FALSE
. I also want to save the plots as JPEG images in a folder called plots/
.
site.par.df <- data.frame(site.ids = c("LMG-05-0009", rep("LMG-05-0004", 2)),
parameters = c(rep("e_coli", 2), "nitrogen_ammonia"),
names = c(rep("E. coli", 2), "Nitrogen Ammonia"),
standards = c(rep(1000, 2), 0.04), log = c(rep(TRUE, 2), FALSE),
stringsAsFactors = FALSE)
site.par.df$main.titles <- paste("Site", site.par.df$site.ids)
site.par.df
## site.ids parameters names standards log
## 1 LMG-05-0009 e_coli E. coli 1e+03 TRUE
## 2 LMG-05-0004 e_coli E. coli 1e+03 TRUE
## 3 LMG-05-0004 nitrogen_ammonia Nitrogen Ammonia 4e-02 FALSE
## main.titles
## 1 Site LMG-05-0009
## 2 Site LMG-05-0004
## 3 Site LMG-05-0004
precipPlot(data = wide.precip.df, sites = site.par.df$site.ids, substances = site.par.df$parameters,
substance.names = site.par.df$names, titles = main.titles, standards = site.par.df$standards,
log = site.par.df$log, save = TRUE, all.combos = FALSE, file.prefix = "plots/",
file.extension = "jpeg")