From 26e97b199fa32f01e3a2bffafd7fa4b193f23c52 Mon Sep 17 00:00:00 2001 From: Sebastian Henz <sebastian.henz@ufz.de> Date: Mon, 19 Oct 2020 16:48:28 +0200 Subject: [PATCH] Refactor the "which" argument in the plot functions closes #57 Use the names as default values. NA will draw only the axes. Update documentation. --- DESCRIPTION | 4 ++-- NEWS.md | 7 +++++++ R/plot_ecxsys.R | 17 +++++++++-------- R/plot_stress.R | 31 +++++++++++++------------------ R/plot_survival.R | 34 +++++++++++++++------------------- man/plot_ecxsys.Rd | 22 ++++++++++++---------- 6 files changed, 58 insertions(+), 57 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e6f968e..fdf2225 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ 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"), diff --git a/NEWS.md b/NEWS.md index beb7e46..983f36a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,14 @@ +# 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. diff --git a/R/plot_ecxsys.R b/R/plot_ecxsys.R index 15658e9..a35f985 100644 --- a/R/plot_ecxsys.R +++ b/R/plot_ecxsys.R @@ -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 diff --git a/R/plot_stress.R b/R/plot_stress.R index f3dfd0b..4b027ea 100644 --- a/R/plot_stress.R +++ b/R/plot_stress.R @@ -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 diff --git a/R/plot_survival.R b/R/plot_survival.R index f99d9fb..7138bca 100644 --- a/R/plot_survival.R +++ b/R/plot_survival.R @@ -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 diff --git a/man/plot_ecxsys.Rd b/man/plot_ecxsys.Rd index ae35a65..1abfe99 100644 --- a/man/plot_ecxsys.Rd +++ b/man/plot_ecxsys.Rd @@ -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 -- GitLab