Skip to content
Snippets Groups Projects
Commit 26e97b19 authored by Sebastian Henz's avatar Sebastian Henz
Browse files

Refactor the "which" argument in the plot functions

closes #57
Use the names as default values.
NA will draw only the axes.
Update documentation.
parent 68bdbe30
No related branches found
No related tags found
No related merge requests found
Package: stressaddition
Type: Package
Title: Modelling Tri-Phasic Concentration-Response Relationships
Version: 3.0.3
Date: 2020-09-21
Version: 3.1.0
Date: 2020-10-19
Authors@R: c(person("Sebastian",
"Henz",
role = c("aut", "cre"),
......
# stressaddition 3.1.0
* Improved the documentation of the `which` argument in `plot_survival()` and `plot_stress()`.
* Changed the default value of the `which` argument in the plot functions. Now it contains the proper default curve names. If it is `NA` only the axes and labels will get drawn.
# stressaddition 3.0.3
* Added references to the journal article about the Multi-Tox model which was recently published.
# stressaddition 3.0.2
* Fixed a bug where the plotting functions printed `NULL` to the console.
......
......@@ -26,14 +26,15 @@
#'
#' @name plot_ecxsys
#'
#' @param model The object returned from \code{\link{ecxsys}}.
#' @param which A vector of names to plot. Allowed are the column names of the
#' \code{model$curves} data frame. There is also
#' \code{"survival_tox_observed"} and \code{"survival_tox_env_observed"} for
#' the observed survival and \code{"sys_tox_observed"} and
#' \code{"sys_tox_env_observed"} for the observed Sys. The default \code{NA}
#' only plots the most important curves. Use \code{which = "all"} to display
#' all curves. An empty vector or \code{NULL} creates just the axes.
#' @param model The model object returned from \code{\link{ecxsys}}.
#' @param which A vector of curve names to plot. Allowed are all values of
#' \code{names(model$curves)} except \code{"concentration"}. See the
#' \emph{Value} section of \code{\link{predict_ecxsys}} for descriptions of
#' these names. Additionally, you can use \code{"survival_tox_observed"} and
#' \code{"survival_tox_env_observed"} for the observed survival and
#' \code{"sys_tox_observed"} and \code{"sys_tox_env_observed"} for the
#' observed Sys. Use \code{"all"} to plot everything or \code{NA} to only draw
#' the axis and labels. Invalid names will be silently ignored.
#'
#' @param show_legend Should the plot include a legend? Defaults to \code{FALSE}
#' because it may cover some parts of the plot depending on the plot size and
......
......@@ -20,7 +20,12 @@
#' @rdname plot_ecxsys
#' @export
plot_stress <- function(model,
which = NA,
which = c(
"sys_tox",
"sys_tox_observed",
"sys_tox_env",
"sys_tox_env_observed"
),
show_legend = FALSE,
xlab = "concentration",
ylab = "stress",
......@@ -30,25 +35,15 @@ plot_stress <- function(model,
curve_names <- names(model$curves)
valid_names <- c(
curve_names[startsWith(curve_names, "stress") | startsWith(curve_names, "sys")],
"sys_tox_observed", "sys_tox_env_observed" # the observed points
"sys_tox_observed"
)
if (length(which) == 1 && is.na(which)) {
which <- c("sys_tox", "sys_tox_observed")
if (model$with_env) {
which <- c(which, "sys_tox_env", "sys_tox_env_observed")
}
} else if ("all" %in% which) {
if (length(which) > 1) {
stop("'all' must not be combined with other curve names.")
}
if (model$with_env) {
valid_names <- c(valid_names, "sys_tox_env_observed")
}
if ("all" %in% which) {
which <- valid_names
} else if (!model$with_env && any(grepl("env", which, fixed = TRUE))) {
warning("'which' contains names with 'env' but the model was built ",
"without environmental stress.")
which <- which[which %in% valid_names]
} else if (any(!which %in% valid_names)) {
warning("Argument 'which' contains invalid names.")
which <- which[which %in% valid_names]
} else {
which <- intersect(which, valid_names)
}
curves <- model$curves
......
......@@ -20,7 +20,14 @@
#' @rdname plot_ecxsys
#' @export
plot_survival <- function(model,
which = NA,
which = c(
"survival_tox",
"survival_tox_sys",
"survival_tox_observed",
"survival_tox_env",
"survival_tox_env_sys",
"survival_tox_env_observed"
),
show_legend = FALSE,
xlab = "concentration",
ylab = "survival",
......@@ -30,26 +37,15 @@ plot_survival <- function(model,
curve_names <- names(model$curves)
valid_names <- c(
curve_names[startsWith(curve_names, "survival")],
"survival_tox_observed", "survival_tox_env_observed" # observed points
"survival_tox_observed"
)
if (length(which) == 1 && is.na(which)) {
which <- c("survival_tox", "survival_tox_sys", "survival_tox_observed")
if (model$with_env) {
which <- c(which, "survival_tox_env", "survival_tox_env_sys",
"survival_tox_env_observed")
}
} else if ("all" %in% which) {
if (length(which) > 1) {
stop("'all' must not be combined with other curve names.")
}
if (model$with_env) {
valid_names <- c(valid_names, "survival_tox_env_observed")
}
if ("all" %in% which) {
which <- valid_names
} else if (!model$with_env && any(grepl("env", which, fixed = TRUE))) {
warning("'which' contains names with 'env' but the model was built ",
"without environmental stress.")
which <- which[which %in% valid_names]
} else if (any(!which %in% valid_names)) {
warning("Argument 'which' contains invalid names.")
which <- which[which %in% valid_names]
} else {
which <- intersect(which, valid_names)
}
curves <- model$curves
......
......@@ -9,7 +9,7 @@
\usage{
plot_stress(
model,
which = NA,
which = c("sys_tox", "sys_tox_observed", "sys_tox_env", "sys_tox_env_observed"),
show_legend = FALSE,
xlab = "concentration",
ylab = "stress",
......@@ -18,7 +18,8 @@ plot_stress(
plot_survival(
model,
which = NA,
which = c("survival_tox", "survival_tox_sys", "survival_tox_observed",
"survival_tox_env", "survival_tox_env_sys", "survival_tox_env_observed"),
show_legend = FALSE,
xlab = "concentration",
ylab = "survival",
......@@ -26,15 +27,16 @@ plot_survival(
)
}
\arguments{
\item{model}{The object returned from \code{\link{ecxsys}}.}
\item{model}{The model object returned from \code{\link{ecxsys}}.}
\item{which}{A vector of names to plot. Allowed are the column names of the
\code{model$curves} data frame. There is also
\code{"survival_tox_observed"} and \code{"survival_tox_env_observed"} for
the observed survival and \code{"sys_tox_observed"} and
\code{"sys_tox_env_observed"} for the observed Sys. The default \code{NA}
only plots the most important curves. Use \code{which = "all"} to display
all curves. An empty vector or \code{NULL} creates just the axes.}
\item{which}{A vector of curve names to plot. Allowed are all values of
\code{names(model$curves)} except \code{"concentration"}. See the
\emph{Value} section of \code{\link{predict_ecxsys}} for descriptions of
these names. Additionally, you can use \code{"survival_tox_observed"} and
\code{"survival_tox_env_observed"} for the observed survival and
\code{"sys_tox_observed"} and \code{"sys_tox_env_observed"} for the
observed Sys. Use \code{"all"} to plot everything or \code{NA} to only draw
the axis and labels. Invalid names will be silently ignored.}
\item{show_legend}{Should the plot include a legend? Defaults to \code{FALSE}
because it may cover some parts of the plot depending on the plot size and
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment