From 6b4ea238555d09ae25d46d4199021f49781e280b Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 19 May 2022 04:29:16 -0400 Subject: [PATCH 1/4] Fixes #273 NA are removed without producing warnings --- R/aaa-utilities.R | 2 ++ R/plot-obs-vs-pred.R | 2 ++ R/plot-res-vs-pred.R | 2 ++ tests/testthat/test-no-na-warnings.R | 32 ++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 tests/testthat/test-no-na-warnings.R diff --git a/R/aaa-utilities.R b/R/aaa-utilities.R index 6e15cdff..5991736b 100644 --- a/R/aaa-utilities.R +++ b/R/aaa-utilities.R @@ -113,6 +113,7 @@ parseAddScatterLayer <- function() { shape = mapLabels$shape ), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$points$size, position = 0, aesthetic = "size"), + na.rm = TRUE, show.legend = TRUE ) }) @@ -163,6 +164,7 @@ parseAddUncertaintyLayer <- function() { # Error bar size uses a ratio of 1/4 to match with point size size = getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$size, position = 0, aesthetic = "size"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$linetype, aesthetic = "linetype"), + na.rm = TRUE, show.legend = TRUE ) } diff --git a/R/plot-obs-vs-pred.R b/R/plot-obs-vs-pred.R index a7a7c19e..7535895a 100644 --- a/R/plot-obs-vs-pred.R +++ b/R/plot-obs-vs-pred.R @@ -57,6 +57,7 @@ plotObsVsPred <- function(data, method = "loess", se = FALSE, formula = "y ~ x", + na.rm = TRUE, mapping = ggplot2::aes_string(x = mapLabels$x, y = mapLabels$y), color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), @@ -71,6 +72,7 @@ plotObsVsPred <- function(data, method = "lm", se = FALSE, formula = "y ~ x", + na.rm = TRUE, color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$size, position = lineIndex, aesthetic = "size") diff --git a/R/plot-res-vs-pred.R b/R/plot-res-vs-pred.R index 0ef30e17..2ae20b10 100644 --- a/R/plot-res-vs-pred.R +++ b/R/plot-res-vs-pred.R @@ -47,6 +47,7 @@ plotResVsPred <- function(data, method = "loess", se = FALSE, formula = "y ~ x", + na.rm = TRUE, mapping = ggplot2::aes_string(x = mapLabels$x, y = mapLabels$y), color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), @@ -61,6 +62,7 @@ plotResVsPred <- function(data, method = "lm", se = FALSE, formula = "y ~ x", + na.rm = TRUE, color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$size, position = lineIndex, aesthetic = "size") diff --git a/tests/testthat/test-no-na-warnings.R b/tests/testthat/test-no-na-warnings.R new file mode 100644 index 00000000..162ac464 --- /dev/null +++ b/tests/testthat/test-no-na-warnings.R @@ -0,0 +1,32 @@ +context("NA data are removed without warnings in scatter plots") + +# Test data that include a NA value +testData <- data.frame( + x = c(1,2,3), + y = c(1,2,NA) +) + +# To prevent copy/paste, expressions are used in the sequel +plotNames <- c("TimeProfile", "ObsVsPred", "ResVsPred", "PKRatio", "DDIRatio") + +# Expression is "DataMapping <- DataMapping$new()" +createDataMapping <- parse(text = paste0(tolower(plotNames), "DataMapping <- ", plotNames, "DataMapping$new(x='x',y='y')")) +eval(createDataMapping) + +# createPlot expression is "plot(data=testData, dataMapping=DataMapping)" +createPlot <- paste0("plot", plotNames, "(data=testData, dataMapping = ", tolower(plotNames), "DataMapping)") +ggplotExpression <- parse(text = paste0('expect_is(', createPlot, ', "ggplot")')) +warningExpression <- parse(text = paste0('expect_silent(', createPlot, ')')) + + +test_that("Plot is produced as a ggplot object", { + expect_is(addScatter(data=testData), "ggplot") + expect_is(addLine(data=testData), "ggplot") + eval(ggplotExpression) +}) + +test_that("No warnings were produced when creating/printing the plot", { + expect_silent(addScatter(data=testData)) + expect_silent(addLine(data=testData)) + eval(warningExpression) +}) From 921edff958bf1a463334a1ea81aa6161e5a16a58 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 19 May 2022 04:31:51 -0400 Subject: [PATCH 2/4] Fixes #272 set transparency for molecular plots --- R/aaa-utilities.R | 3 +++ R/plot-ddiratio.R | 2 ++ R/plot-obs-vs-pred.R | 2 ++ R/plot-res-vs-pred.R | 2 ++ 4 files changed, 9 insertions(+) diff --git a/R/aaa-utilities.R b/R/aaa-utilities.R index 5991736b..23493f04 100644 --- a/R/aaa-utilities.R +++ b/R/aaa-utilities.R @@ -113,6 +113,7 @@ parseAddScatterLayer <- function() { shape = mapLabels$shape ), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$points$size, position = 0, aesthetic = "size"), + alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$points$alpha, aesthetic = "alpha"), na.rm = TRUE, show.legend = TRUE ) @@ -141,6 +142,7 @@ parseAddLineLayer <- function(type, value, position) { ), "color=getAestheticValues(n=1,selectionKey=plotConfiguration$lines$color,position=", position, ',aesthetic="color"),', "linetype=getAestheticValues(n=1,selectionKey=plotConfiguration$lines$linetype,position=", position, ',aesthetic="linetype"),', + "alpha=getAestheticValues(n=1,selectionKey=plotConfiguration$lines$alpha,position=", position, ',aesthetic="alpha"),', "size=getAestheticValues(n=1,selectionKey=plotConfiguration$lines$size,position=", position, ', aesthetic="size"))' )) } @@ -164,6 +166,7 @@ parseAddUncertaintyLayer <- function() { # Error bar size uses a ratio of 1/4 to match with point size size = getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$size, position = 0, aesthetic = "size"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$linetype, aesthetic = "linetype"), + alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$alpha, aesthetic = "linetype"), na.rm = TRUE, show.legend = TRUE ) diff --git a/R/plot-ddiratio.R b/R/plot-ddiratio.R index b00a9ca7..58f5beec 100644 --- a/R/plot-ddiratio.R +++ b/R/plot-ddiratio.R @@ -60,6 +60,7 @@ plotDDIRatio <- function(data, na.rm = TRUE, color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), + alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$alpha, position = lineIndex, aesthetic = "alpha"), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$size, position = lineIndex, aesthetic = "size") ) + ggplot2::geom_path( @@ -68,6 +69,7 @@ plotDDIRatio <- function(data, na.rm = TRUE, color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), + alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$alpha, position = lineIndex, aesthetic = "alpha"), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$size, position = lineIndex, aesthetic = "size") ) diff --git a/R/plot-obs-vs-pred.R b/R/plot-obs-vs-pred.R index 7535895a..18a040f1 100644 --- a/R/plot-obs-vs-pred.R +++ b/R/plot-obs-vs-pred.R @@ -61,6 +61,7 @@ plotObsVsPred <- function(data, mapping = ggplot2::aes_string(x = mapLabels$x, y = mapLabels$y), color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), + alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$alpha, position = lineIndex, aesthetic = "alpha"), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$size, position = lineIndex, aesthetic = "size") ) } @@ -75,6 +76,7 @@ plotObsVsPred <- function(data, na.rm = TRUE, color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), + alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$alpha, position = lineIndex, aesthetic = "alpha"), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$size, position = lineIndex, aesthetic = "size") ) } diff --git a/R/plot-res-vs-pred.R b/R/plot-res-vs-pred.R index 2ae20b10..c061ebe9 100644 --- a/R/plot-res-vs-pred.R +++ b/R/plot-res-vs-pred.R @@ -51,6 +51,7 @@ plotResVsPred <- function(data, mapping = ggplot2::aes_string(x = mapLabels$x, y = mapLabels$y), color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), + alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$alpha, position = lineIndex, aesthetic = "alpha"), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$size, position = lineIndex, aesthetic = "size") ) } @@ -65,6 +66,7 @@ plotResVsPred <- function(data, na.rm = TRUE, color = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$color, position = lineIndex, aesthetic = "color"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$linetype, position = lineIndex, aesthetic = "linetype"), + alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$alpha, position = lineIndex, aesthetic = "alpha"), size = getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$size, position = lineIndex, aesthetic = "size") ) } From e5c5b560d242c596a84d423f3403059a09417c28 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 19 May 2022 04:40:13 -0400 Subject: [PATCH 3/4] Update line layer in scatter plots --- R/aaa-utilities.R | 7 ++++--- R/plot-ddiratio.R | 4 ++-- R/plot-obs-vs-pred.R | 3 ++- R/plot-res-vs-pred.R | 3 ++- man/parseAddLineLayer.Rd | 5 +++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/R/aaa-utilities.R b/R/aaa-utilities.R index 23493f04..156d851c 100644 --- a/R/aaa-utilities.R +++ b/R/aaa-utilities.R @@ -33,7 +33,7 @@ parseVariableFromObject <- function(objectName, variableName, keepIfNull = FALSE #' @return An expression to `eval()` #' @keywords internal parseValueToObject <- function(objectName, value) { - if (isOfLength(value, 0)) { + if (isEmpty(value)) { return(parse(text = paste0(objectName, " <- NULL"))) } if (isOfType(value, "character")) { @@ -122,11 +122,12 @@ parseAddScatterLayer <- function() { #' @title parseAddLineLayer #' @description Create an expression that adds scatter plot layer +#' TODO: create a vignette explaining how argument `lines` in dataMapping is related to this #' @param type one of "horizontal", "vertical" or "diagonal" #' Note that for "diagonal", geom_abline is used. #' `value` of intercept is taken as is for linear scale but corresponds to the log of `value` for log scale. -#' For instance, intercept = c(-1, 0, 1) actually means that the line will go through c(0.1, 1, 10) for x=1 -#' because log10(c(-1, 0, 1)) = c(0.1, 1, 10). +#' For instance, intercept = c(-1, 0, 1) with log scale actually means that the line will go through c(0.1, 1, 10) +#' because c(-1, 0, 1) = log10(c(0.1, 1, 10)). #' @param value value of xintercept or yintercept #' @param position line position for aesthetic properties #' @return An expression to `eval()` diff --git a/R/plot-ddiratio.R b/R/plot-ddiratio.R index 58f5beec..c4680944 100644 --- a/R/plot-ddiratio.R +++ b/R/plot-ddiratio.R @@ -42,12 +42,12 @@ plotDDIRatio <- function(data, if(residualsVsObserved){ lineOrientation <- "ddiHorizontal" } - # Include horizontal lines + # Include diagonal or horizontal lines depending on the plot type for (lineIndex in seq_along(dataMapping$lines)) { # position correspond to the number of layer lines already added eval(parseAddLineLayer(lineOrientation, dataMapping$lines[[lineIndex]], lineIndex - 1)) } - if (isOfLength(lineIndex, 0)) { + if (isEmpty(lineIndex)) { lineIndex <- 0 } # Add Guest et al. lines to plot diff --git a/R/plot-obs-vs-pred.R b/R/plot-obs-vs-pred.R index 18a040f1..da5710aa 100644 --- a/R/plot-obs-vs-pred.R +++ b/R/plot-obs-vs-pred.R @@ -43,10 +43,11 @@ plotObsVsPred <- function(data, plotObject <- plotObject %||% initializePlot(plotConfiguration) + # Add diagonal lines with offset defined in lines of dataMapping for (lineIndex in seq_along(dataMapping$lines)) { eval(parseAddLineLayer("diagonal", dataMapping$lines[[lineIndex]], lineIndex - 1)) } - if (isOfLength(lineIndex, 0)) { + if (isEmpty(lineIndex)) { lineIndex <- 0 } # Add Smoother if defined diff --git a/R/plot-res-vs-pred.R b/R/plot-res-vs-pred.R index c061ebe9..1cbecc03 100644 --- a/R/plot-res-vs-pred.R +++ b/R/plot-res-vs-pred.R @@ -33,10 +33,11 @@ plotResVsPred <- function(data, plotObject <- plotObject %||% initializePlot(plotConfiguration) + # Add horizontal lines with offset defined in lines of dataMapping for (lineIndex in seq_along(dataMapping$lines)) { eval(parseAddLineLayer("horizontal", dataMapping$lines[[lineIndex]], lineIndex - 1)) } - if (isOfLength(lineIndex, 0)) { + if (isEmpty(lineIndex)) { lineIndex <- 0 } # Add Smoother if defined diff --git a/man/parseAddLineLayer.Rd b/man/parseAddLineLayer.Rd index 73cc2af9..dd9030d9 100644 --- a/man/parseAddLineLayer.Rd +++ b/man/parseAddLineLayer.Rd @@ -10,8 +10,8 @@ parseAddLineLayer(type, value, position) \item{type}{one of "horizontal", "vertical" or "diagonal" Note that for "diagonal", geom_abline is used. \code{value} of intercept is taken as is for linear scale but corresponds to the log of \code{value} for log scale. -For instance, intercept = c(-1, 0, 1) actually means that the line will go through c(0.1, 1, 10) for x=1 -because log10(c(-1, 0, 1)) = c(0.1, 1, 10).} +For instance, intercept = c(-1, 0, 1) with log scale actually means that the line will go through c(0.1, 1, 10) +because c(-1, 0, 1) = log10(c(0.1, 1, 10)).} \item{value}{value of xintercept or yintercept} @@ -22,5 +22,6 @@ An expression to \code{eval()} } \description{ Create an expression that adds scatter plot layer +TODO: create a vignette explaining how argument \code{lines} in dataMapping is related to this } \keyword{internal} From 2944e702481568591d38ad8b494a91c50f72e4f9 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 19 May 2022 05:48:50 -0400 Subject: [PATCH 4/4] Fix typo --- R/aaa-utilities.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/aaa-utilities.R b/R/aaa-utilities.R index 156d851c..749d9746 100644 --- a/R/aaa-utilities.R +++ b/R/aaa-utilities.R @@ -167,7 +167,7 @@ parseAddUncertaintyLayer <- function() { # Error bar size uses a ratio of 1/4 to match with point size size = getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$size, position = 0, aesthetic = "size"), linetype = getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$linetype, aesthetic = "linetype"), - alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$alpha, aesthetic = "linetype"), + alpha = getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$alpha, aesthetic = "alpha"), na.rm = TRUE, show.legend = TRUE )