From c6ac0458019b4dd96c39dc5ce9421996826f315b Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 29 Apr 2022 08:34:50 -0400 Subject: [PATCH 1/3] Fixes #249 allow data expansion to axes Default value for ddi ratio is TRUE --- R/plotconfiguration-axis.R | 58 ++++++++++++++++++++++++++++++++----- R/plotconfiguration.R | 10 +++++-- R/utilities-axis.R | 59 +++++++++++++++++++++++++++++++++++--- man/AxisConfiguration.Rd | 25 +++++++++++++++- man/XAxisConfiguration.Rd | 1 + man/YAxisConfiguration.Rd | 1 + man/setXAxis.Rd | 5 +++- man/setYAxis.Rd | 5 +++- man/xAxisDefaultExpand.Rd | 33 +++++++++++++++++++++ man/yAxisDefaultExpand.Rd | 33 +++++++++++++++++++++ 10 files changed, 214 insertions(+), 16 deletions(-) create mode 100644 man/xAxisDefaultExpand.Rd create mode 100644 man/yAxisDefaultExpand.Rd diff --git a/R/plotconfiguration-axis.R b/R/plotconfiguration-axis.R index 3ffe47c7..7291fc10 100644 --- a/R/plotconfiguration-axis.R +++ b/R/plotconfiguration-axis.R @@ -38,7 +38,6 @@ createPlotTicks <- function(ticks) { return(ticks) } - #' @title AxisConfiguration #' @description R6 class defining the configuration of axis #' @export @@ -52,20 +51,26 @@ AxisConfiguration <- R6::R6Class( #' @param ticks numeric vector or function defining where to position axis ticks #' @param ticklabels character vector or function defining what to print on axis ticks #' @param font `Font` object defining the font of ticklabels + #' @param expand logical defining if data is expanded until axis. + #' If `TRUE`, data is expanded until axis + #' If `FALSE`, some space between data and axis is kept #' @return A new `AxisConfiguration` object initialize = function(limits = NULL, scale = Scaling$lin, ticks = NULL, ticklabels = NULL, - font = NULL) { + font = NULL, + expand = FALSE) { validateIsNumeric(limits, nullAllowed = TRUE) validateIsOfType(font, "Font", nullAllowed = TRUE) + validateIsLogical(expand) private$.limits <- limits scale <- scale %||% Scaling$lin private$.scale <- createPlotScale(scale) private$.ticks <- createPlotTicks(ticks) private$.ticklabels <- createPlotTicks(ticklabels) + private$.expand <- expand # Default axis font will use theme defaultFont <- Font$new() @@ -90,6 +95,15 @@ AxisConfiguration <- R6::R6Class( ) }, + #' @description Get the `ggplot2` actual function for expansion + #' @return A `ggplot2` function + ggplotExpansion = function() { + if (private$.expand) { + return(ggplot2::expansion()) + } + return(ggplot2::waiver()) + }, + #' @description Get tick values for pretty default log plots #' @return User defined tick values or tlf default ticks prettyTicks = function() { @@ -185,6 +199,17 @@ AxisConfiguration <- R6::R6Class( } private$.font <- value %||% defaultFont return(invisible()) + }, + #' @field expand logical defining if data is expanded until axis. + #' If `TRUE`, data is expanded until axis + #' If `FALSE`, some space between data and axis is kept + expand = function(value) { + if (missing(value)) { + return(private$.expand) + } + validateIsLogical(value) + private$.expand <- value + return(invisible()) } ), private = list( @@ -192,7 +217,8 @@ AxisConfiguration <- R6::R6Class( .scale = NULL, .ticks = NULL, .ticklabels = NULL, - .font = NULL + .font = NULL, + .expand = NULL ) ) @@ -219,7 +245,11 @@ XAxisConfiguration <- R6::R6Class( if (isIncluded(private$.scale, Scaling$discrete)) { suppressMessages( plotObject <- plotObject + - ggplot2::scale_x_discrete(breaks = private$.ticks, labels = private$.ticklabels) + ggplot2::scale_x_discrete( + breaks = private$.ticks, + labels = private$.ticklabels, + expand = self$ggplotExpansion() + ) ) return(plotObject) } @@ -227,7 +257,12 @@ XAxisConfiguration <- R6::R6Class( # `try` should be added in cases of scale breaking because all the ggplot object elements are not yet in place suppressMessages( plotObject <- plotObject + - ggplot2::scale_x_continuous(trans = self$ggplotScale(), breaks = self$prettyTicks(), labels = self$prettyTickLabels()) + ggplot2::scale_x_continuous( + trans = self$ggplotScale(), + breaks = self$prettyTicks(), + labels = self$prettyTickLabels(), + expand = self$ggplotExpansion() + ) ) # Add special tick lines for pretty log plots suppressMessages( @@ -268,7 +303,11 @@ YAxisConfiguration <- R6::R6Class( if (isIncluded(private$.scale, Scaling$discrete)) { suppressMessages( plotObject <- plotObject + - ggplot2::scale_y_discrete(breaks = private$.ticks, labels = private$.ticklabels) + ggplot2::scale_y_discrete( + breaks = private$.ticks, + labels = private$.ticklabels, + expand = self$ggplotExpansion() + ) ) return(plotObject) } @@ -276,7 +315,12 @@ YAxisConfiguration <- R6::R6Class( # `try` should be added in cases of scale breaking because all the ggplot object elements are not yet in place suppressMessages( plotObject <- plotObject + - ggplot2::scale_y_continuous(trans = self$ggplotScale(), breaks = self$prettyTicks(), labels = self$prettyTickLabels()) + ggplot2::scale_y_continuous( + trans = self$ggplotScale(), + breaks = self$prettyTicks(), + labels = self$prettyTickLabels(), + expand = self$ggplotExpansion() + ) ) # Add special tick lines for pretty log plots suppressMessages( diff --git a/R/plotconfiguration.R b/R/plotconfiguration.R index 2c2eb0cb..05ded3fc 100644 --- a/R/plotconfiguration.R +++ b/R/plotconfiguration.R @@ -122,13 +122,19 @@ PlotConfiguration <- R6::R6Class( # X-Axis Configuration, overwrite some properties only if they are defined validateIsOfType(xAxis, "XAxisConfiguration", nullAllowed = TRUE) - private$.xAxis <- xAxis %||% XAxisConfiguration$new(scale = xAxisDefaultScale(self)) + private$.xAxis <- xAxis %||% XAxisConfiguration$new( + scale = xAxisDefaultScale(self), + expand = xAxisDefaultExpand(self) + ) private$.xAxis$limits <- xLimits %||% private$.xAxis$limits private$.xAxis$scale <- xScale %||% private$.xAxis$scale # Y-Axis configuration, overwrite some properties only if they are defined validateIsOfType(yAxis, "YAxisConfiguration", nullAllowed = TRUE) - private$.yAxis <- yAxis %||% YAxisConfiguration$new(scale = yAxisDefaultScale(self)) + private$.yAxis <- yAxis %||% YAxisConfiguration$new( + scale = yAxisDefaultScale(self), + expand = xAxisDefaultExpand(self) + ) private$.yAxis$limits <- yLimits %||% private$.yAxis$limits private$.yAxis$scale <- yScale %||% private$.yAxis$scale diff --git a/R/utilities-axis.R b/R/utilities-axis.R index d6be03be..e23b807e 100644 --- a/R/utilities-axis.R +++ b/R/utilities-axis.R @@ -43,6 +43,7 @@ Scaling <- enum(c( #' @param ticks Optional values or function for axis ticks #' @param ticklabels Optional values or function for axis ticklabels #' @param font A `Font` object defining font of ticklabels +#' @param expand Logical defining if data is expanded until axis #' @return A `ggplot` object #' @export #' @examples @@ -64,11 +65,13 @@ setXAxis <- function(plotObject, limits = NULL, ticks = NULL, ticklabels = NULL, - font = NULL) { + font = NULL, + expand = NULL) { validateIsOfType(plotObject, "ggplot") validateIsIncluded(scale, Scaling, nullAllowed = TRUE) validateIsNumeric(limits, nullAllowed = TRUE) validateIsOfType(font, "Font", nullAllowed = TRUE) + validateIsLogical(expand, nullAllowed = TRUE) # Clone plotConfiguration into a new plot object # Prevents update of R6 class being spread to plotObject @@ -77,7 +80,7 @@ setXAxis <- function(plotObject, # R6 class not cloned will spread modifications into newPlotObject$plotConfiguration$xAxis xAxis <- newPlotObject$plotConfiguration$xAxis - eval(parseVariableToObject("xAxis", c("limits", "scale", "ticks", "ticklabels", "font"), keepIfNull = TRUE)) + eval(parseVariableToObject("xAxis", c("limits", "scale", "ticks", "ticklabels", "font", "expand"), keepIfNull = TRUE)) newPlotObject <- xAxis$updatePlot(newPlotObject, ylim = newPlotObject$plotConfiguration$yAxis$limits) return(newPlotObject) } @@ -106,11 +109,13 @@ setYAxis <- function(plotObject, limits = NULL, ticks = NULL, ticklabels = NULL, - font = NULL) { + font = NULL, + expand = NULL) { validateIsOfType(plotObject, "ggplot") validateIsIncluded(scale, Scaling, nullAllowed = TRUE) validateIsNumeric(limits, nullAllowed = TRUE) validateIsOfType(font, "Font", nullAllowed = TRUE) + validateIsLogical(expand, nullAllowed = TRUE) # Clone plotConfiguration into a new plot object # Prevents update of R6 class being spread to plotObject @@ -119,7 +124,7 @@ setYAxis <- function(plotObject, # R6 class not cloned will spread modifications into newPlotObject$plotConfiguration$yAxis yAxis <- newPlotObject$plotConfiguration$yAxis - eval(parseVariableToObject("yAxis", c("limits", "scale", "ticks", "ticklabels", "font"), keepIfNull = TRUE)) + eval(parseVariableToObject("yAxis", c("limits", "scale", "ticks", "ticklabels", "font", "expand"), keepIfNull = TRUE)) newPlotObject <- yAxis$updatePlot(newPlotObject, xlim = newPlotObject$plotConfiguration$xAxis$limits) return(newPlotObject) } @@ -233,3 +238,49 @@ getSqrtTickLabels <- function(ticks) { sqrtValues <- ticks^2 return(parse(text = paste("sqrt(", sqrtValues, ")", sep = ""))) } + +#' @title xAxisDefaultExpand +#' @description Return x-axis default expand from a plot configuration +#' @param plotConfiguration A `PlotConfiguration` object +#' @return The default expand. +#' @examples +#' \dontrun{ +#' # Regular plots use continuous linear scale for x-axis +#' plotConfiguration <- PlotConfiguration$new() +#' xAxisDefaultExpand(plotConfiguration) +#' +#' # DDI plots use log scale for x-axis +#' ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() +#' xAxisDefaultExpand(ddiPlotConfiguration) +#' +#' # Boxplots use discrete scale for x-axis +#' boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() +#' xAxisDefaultExpand(boxPlotConfiguration) +#' } +#' @keywords internal +xAxisDefaultExpand <- function(plotConfiguration) { + return(isOfType(plotConfiguration, c("DDIRatioPlotConfiguration"))) +} + +#' @title yAxisDefaultExpand +#' @description Return x-axis default expand from a plot configuration +#' @param plotConfiguration A `PlotConfiguration` object +#' @return The default expand. +#' @examples +#' \dontrun{ +#' # Regular plots use continuous linear scale for x-axis +#' plotConfiguration <- PlotConfiguration$new() +#' yAxisDefaultExpand(plotConfiguration) +#' +#' # DDI plots use log scale for x-axis +#' ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() +#' yAxisDefaultExpand(ddiPlotConfiguration) +#' +#' # Boxplots use discrete scale for x-axis +#' boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() +#' yAxisDefaultExpand(boxPlotConfiguration) +#' } +#' @keywords internal +yAxisDefaultExpand <- function(plotConfiguration) { + return(isOfType(plotConfiguration, c("DDIRatioPlotConfiguration"))) +} diff --git a/man/AxisConfiguration.Rd b/man/AxisConfiguration.Rd index c6ffaa1d..bf9531aa 100644 --- a/man/AxisConfiguration.Rd +++ b/man/AxisConfiguration.Rd @@ -20,6 +20,10 @@ A value of \code{NULL} is allowed and will lead to a default linear scale} \item{\code{ticklabels}}{function or values defining the axis tick labels} \item{\code{font}}{\code{Font} object defining the font of the ticklabels} + +\item{\code{expand}}{logical defining if data is expanded until axis. +If \code{TRUE}, data is expanded until axis +If \code{FALSE}, some space between data and axis is kept} } \if{html}{\out{}} } @@ -28,6 +32,7 @@ A value of \code{NULL} is allowed and will lead to a default linear scale} \itemize{ \item \href{#method-new}{\code{AxisConfiguration$new()}} \item \href{#method-ggplotScale}{\code{AxisConfiguration$ggplotScale()}} +\item \href{#method-ggplotExpansion}{\code{AxisConfiguration$ggplotExpansion()}} \item \href{#method-prettyTicks}{\code{AxisConfiguration$prettyTicks()}} \item \href{#method-prettyTickLabels}{\code{AxisConfiguration$prettyTickLabels()}} \item \href{#method-clone}{\code{AxisConfiguration$clone()}} @@ -44,7 +49,8 @@ Create a new \code{AxisConfiguration} object scale = Scaling$lin, ticks = NULL, ticklabels = NULL, - font = NULL + font = NULL, + expand = FALSE )}\if{html}{\out{}} } @@ -61,6 +67,10 @@ Use enum \code{Scaling} to access predefined scales.} \item{\code{ticklabels}}{character vector or function defining what to print on axis ticks} \item{\code{font}}{\code{Font} object defining the font of ticklabels} + +\item{\code{expand}}{logical defining if data is expanded until axis. +If \code{TRUE}, data is expanded until axis +If \code{FALSE}, some space between data and axis is kept} } \if{html}{\out{}} } @@ -82,6 +92,19 @@ A character included in \code{ggplot2} available \code{trans} names } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ggplotExpansion}{}}} +\subsection{Method \code{ggplotExpansion()}}{ +Get the \code{ggplot2} actual function for expansion +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{AxisConfiguration$ggplotExpansion()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +A \code{ggplot2} function +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-prettyTicks}{}}} \subsection{Method \code{prettyTicks()}}{ diff --git a/man/XAxisConfiguration.Rd b/man/XAxisConfiguration.Rd index 6d746d67..aee9a024 100644 --- a/man/XAxisConfiguration.Rd +++ b/man/XAxisConfiguration.Rd @@ -19,6 +19,7 @@ R6 class defining the configuration of X-axis \if{html}{ \out{
Inherited methods} \itemize{ +\item \out{}\href{../../tlf/html/AxisConfiguration.html#method-ggplotExpansion}{\code{tlf::AxisConfiguration$ggplotExpansion()}}\out{} \item \out{}\href{../../tlf/html/AxisConfiguration.html#method-ggplotScale}{\code{tlf::AxisConfiguration$ggplotScale()}}\out{} \item \out{}\href{../../tlf/html/AxisConfiguration.html#method-initialize}{\code{tlf::AxisConfiguration$initialize()}}\out{} \item \out{}\href{../../tlf/html/AxisConfiguration.html#method-prettyTickLabels}{\code{tlf::AxisConfiguration$prettyTickLabels()}}\out{} diff --git a/man/YAxisConfiguration.Rd b/man/YAxisConfiguration.Rd index 28086547..bb7da7dd 100644 --- a/man/YAxisConfiguration.Rd +++ b/man/YAxisConfiguration.Rd @@ -26,6 +26,7 @@ R6 class defining the configuration of Y-axis \if{html}{ \out{
Inherited methods} \itemize{ +\item \out{}\href{../../tlf/html/AxisConfiguration.html#method-ggplotExpansion}{\code{tlf::AxisConfiguration$ggplotExpansion()}}\out{} \item \out{}\href{../../tlf/html/AxisConfiguration.html#method-ggplotScale}{\code{tlf::AxisConfiguration$ggplotScale()}}\out{} \item \out{}\href{../../tlf/html/AxisConfiguration.html#method-initialize}{\code{tlf::AxisConfiguration$initialize()}}\out{} \item \out{}\href{../../tlf/html/AxisConfiguration.html#method-prettyTickLabels}{\code{tlf::AxisConfiguration$prettyTickLabels()}}\out{} diff --git a/man/setXAxis.Rd b/man/setXAxis.Rd index f64d3873..22281f67 100644 --- a/man/setXAxis.Rd +++ b/man/setXAxis.Rd @@ -10,7 +10,8 @@ setXAxis( limits = NULL, ticks = NULL, ticklabels = NULL, - font = NULL + font = NULL, + expand = NULL ) } \arguments{ @@ -25,6 +26,8 @@ setXAxis( \item{ticklabels}{Optional values or function for axis ticklabels} \item{font}{A \code{Font} object defining font of ticklabels} + +\item{expand}{Logical defining if data is expanded until axis} } \value{ A \code{ggplot} object diff --git a/man/setYAxis.Rd b/man/setYAxis.Rd index c79ca8c9..2658e9b8 100644 --- a/man/setYAxis.Rd +++ b/man/setYAxis.Rd @@ -10,7 +10,8 @@ setYAxis( limits = NULL, ticks = NULL, ticklabels = NULL, - font = NULL + font = NULL, + expand = NULL ) } \arguments{ @@ -25,6 +26,8 @@ setYAxis( \item{ticklabels}{Optional values or function for axis ticklabels} \item{font}{A \code{Font} object defining font of ticklabels} + +\item{expand}{Logical defining if data is expanded until axis} } \value{ A \code{ggplot} object diff --git a/man/xAxisDefaultExpand.Rd b/man/xAxisDefaultExpand.Rd new file mode 100644 index 00000000..6892025c --- /dev/null +++ b/man/xAxisDefaultExpand.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utilities-axis.R +\name{xAxisDefaultExpand} +\alias{xAxisDefaultExpand} +\title{xAxisDefaultExpand} +\usage{ +xAxisDefaultExpand(plotConfiguration) +} +\arguments{ +\item{plotConfiguration}{A \code{PlotConfiguration} object} +} +\value{ +The default expand. +} +\description{ +Return x-axis default expand from a plot configuration +} +\examples{ +\dontrun{ +# Regular plots use continuous linear scale for x-axis +plotConfiguration <- PlotConfiguration$new() +xAxisDefaultExpand(plotConfiguration) + +# DDI plots use log scale for x-axis +ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() +xAxisDefaultExpand(ddiPlotConfiguration) + +# Boxplots use discrete scale for x-axis +boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() +xAxisDefaultExpand(boxPlotConfiguration) +} +} +\keyword{internal} diff --git a/man/yAxisDefaultExpand.Rd b/man/yAxisDefaultExpand.Rd new file mode 100644 index 00000000..1b843dcc --- /dev/null +++ b/man/yAxisDefaultExpand.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utilities-axis.R +\name{yAxisDefaultExpand} +\alias{yAxisDefaultExpand} +\title{yAxisDefaultExpand} +\usage{ +yAxisDefaultExpand(plotConfiguration) +} +\arguments{ +\item{plotConfiguration}{A \code{PlotConfiguration} object} +} +\value{ +The default expand. +} +\description{ +Return x-axis default expand from a plot configuration +} +\examples{ +\dontrun{ +# Regular plots use continuous linear scale for x-axis +plotConfiguration <- PlotConfiguration$new() +yAxisDefaultExpand(plotConfiguration) + +# DDI plots use log scale for x-axis +ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() +yAxisDefaultExpand(ddiPlotConfiguration) + +# Boxplots use discrete scale for x-axis +boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() +yAxisDefaultExpand(boxPlotConfiguration) +} +} +\keyword{internal} From 9d7678adee762a835efcfbc338b8844c1ef62029 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 29 Apr 2022 11:07:05 -0400 Subject: [PATCH 2/3] Default axes scales and expand are managed using constants --- R/boxwhisker-plotconfiguration.R | 3 + R/plotconfiguration.R | 30 +++++++-- R/tornado-plotconfiguration.R | 2 + R/utilities-axis.R | 105 ----------------------------- man/BoxWhiskerPlotConfiguration.Rd | 7 ++ man/DDIRatioPlotConfiguration.Rd | 11 +++ man/PKRatioPlotConfiguration.Rd | 7 ++ man/PlotConfiguration.Rd | 6 ++ man/TornadoPlotConfiguration.Rd | 2 + man/xAxisDefaultExpand.Rd | 33 --------- man/xAxisDefaultScale.Rd | 34 ---------- man/yAxisDefaultExpand.Rd | 33 --------- man/yAxisDefaultScale.Rd | 34 ---------- 13 files changed, 62 insertions(+), 245 deletions(-) delete mode 100644 man/xAxisDefaultExpand.Rd delete mode 100644 man/xAxisDefaultScale.Rd delete mode 100644 man/yAxisDefaultExpand.Rd delete mode 100644 man/yAxisDefaultScale.Rd diff --git a/R/boxwhisker-plotconfiguration.R b/R/boxwhisker-plotconfiguration.R index c194fefe..04005916 100644 --- a/R/boxwhisker-plotconfiguration.R +++ b/R/boxwhisker-plotconfiguration.R @@ -6,6 +6,9 @@ BoxWhiskerPlotConfiguration <- R6::R6Class( "BoxWhiskerPlotConfiguration", inherit = PlotConfiguration, public = list( + #' @field defaultXScale Default xAxis scale value when creating a `BoxWhiskerPlotConfiguration` object + defaultXScale = Scaling$discrete, + #' @description Create a new `BoxWhiskerPlotConfiguration` object #' @param outliers logical defining if outliers should be included in boxplot #' @param ... parameters inherited from `PlotConfiguration` diff --git a/R/plotconfiguration.R b/R/plotconfiguration.R index 05ded3fc..17d22abf 100644 --- a/R/plotconfiguration.R +++ b/R/plotconfiguration.R @@ -1,6 +1,9 @@ #' @title PlotConfiguration #' @description R6 class defining the configuration of a `ggplot` object #' @field export R6 class `ExportConfiguration` defining properties for saving/exporting plota +#' @field defaultXScale Default xAxis scale value when creating a `PlotConfiguration` object +#' @field defaultYScale Default yAxis scale value when creating a `PlotConfiguration` object +#' @field defaultExpand Default expand value when creating a `PlotConfiguration` object #' @family PlotConfiguration classes #' @references For examples, see: #' @@ -9,6 +12,9 @@ PlotConfiguration <- R6::R6Class( "PlotConfiguration", public = list( export = NULL, + defaultXScale = Scaling$lin, + defaultYScale = Scaling$lin, + defaultExpand = FALSE, #' @description Create a new `PlotConfiguration` object #' @param title character or `Label` object defining plot title @@ -123,8 +129,8 @@ PlotConfiguration <- R6::R6Class( # X-Axis Configuration, overwrite some properties only if they are defined validateIsOfType(xAxis, "XAxisConfiguration", nullAllowed = TRUE) private$.xAxis <- xAxis %||% XAxisConfiguration$new( - scale = xAxisDefaultScale(self), - expand = xAxisDefaultExpand(self) + scale = self$defaultXScale, + expand = self$defaultExpand ) private$.xAxis$limits <- xLimits %||% private$.xAxis$limits private$.xAxis$scale <- xScale %||% private$.xAxis$scale @@ -132,8 +138,8 @@ PlotConfiguration <- R6::R6Class( # Y-Axis configuration, overwrite some properties only if they are defined validateIsOfType(yAxis, "YAxisConfiguration", nullAllowed = TRUE) private$.yAxis <- yAxis %||% YAxisConfiguration$new( - scale = yAxisDefaultScale(self), - expand = xAxisDefaultExpand(self) + scale = self$defaultYScale, + expand = self$defaultExpand ) private$.yAxis$limits <- yLimits %||% private$.yAxis$limits private$.yAxis$scale <- yScale %||% private$.yAxis$scale @@ -278,20 +284,32 @@ TimeProfilePlotConfiguration <- R6::R6Class( #' @title PKRatioPlotConfiguration #' @description R6 class defining the configuration of a `ggplot` object for PK ratio plots +#' @field defaultYScale Default yAxis scale value when creating a `PKRatioPlotConfiguration` object #' @export #' @family PlotConfiguration classes PKRatioPlotConfiguration <- R6::R6Class( "PKRatioPlotConfiguration", - inherit = PlotConfiguration + inherit = PlotConfiguration, + public = list( + defaultYScale = Scaling$log + ) ) #' @title DDIRatioPlotConfiguration #' @description R6 class defining the configuration of a `ggplot` object for DDI ratio plots +#' @field defaultXScale Default xAxis scale value when creating a `DDIRatioPlotConfiguration` object +#' @field defaultYScale Default yAxis scale value when creating a `DDIRatioPlotConfiguration` object +#' @field defaultExpand Default expand value when creating a `DDIRatioPlotConfiguration` object #' @export #' @family PlotConfiguration classes DDIRatioPlotConfiguration <- R6::R6Class( "DDIRatioPlotConfiguration", - inherit = PlotConfiguration + inherit = PlotConfiguration, + public = list( + defaultXScale = Scaling$log, + defaultYScale = Scaling$log, + defaultExpand = TRUE + ) ) #' @title ObsVsPredPlotConfiguration diff --git a/R/tornado-plotconfiguration.R b/R/tornado-plotconfiguration.R index ebabcff6..0c95f953 100644 --- a/R/tornado-plotconfiguration.R +++ b/R/tornado-plotconfiguration.R @@ -12,6 +12,8 @@ TornadoPlotConfiguration <- R6::R6Class( colorPalette = NULL, #' @field dodge space between the bars/points dodge = NULL, + #' @field defaultYScale Default yAxis scale value when creating a `TornadoPlotConfiguration` object + defaultYScale = Scaling$discrete, #' @description Create a new `TornadoPlotConfiguration` object #' @param bar logical setting if tornado is uses a bar plot instead of regular points diff --git a/R/utilities-axis.R b/R/utilities-axis.R index e23b807e..011887de 100644 --- a/R/utilities-axis.R +++ b/R/utilities-axis.R @@ -129,65 +129,6 @@ setYAxis <- function(plotObject, return(newPlotObject) } -#' @title xAxisDefaultScale -#' @description Return x-axis default scale from a plot configuration -#' @param plotConfiguration A `PlotConfiguration` object -#' @return The default scale. -#' The enum `Scaling` provides a list of available scales. -#' @examples -#' \dontrun{ -#' # Regular plots use continuous linear scale for x-axis -#' plotConfiguration <- PlotConfiguration$new() -#' xAxisDefaultScale(plotConfiguration) -#' -#' # DDI plots use log scale for x-axis -#' ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() -#' xAxisDefaultScale(ddiPlotConfiguration) -#' -#' # Boxplots use discrete scale for x-axis -#' boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() -#' xAxisDefaultScale(boxPlotConfiguration) -#' } -#' @keywords internal -xAxisDefaultScale <- function(plotConfiguration) { - if (isOfType(plotConfiguration, c("DDIRatioPlotConfiguration"))) { - return(Scaling$log) - } - if (isOfType(plotConfiguration, c("BoxWhiskerPlotConfiguration"))) { - return(Scaling$discrete) - } - return(Scaling$lin) -} - -#' @title yAxisDefaultScale -#' @description Return y-axis default scale from a plot configuration -#' @param plotConfiguration A `PlotConfiguration` object -#' @return The default scale. -#' The enum `Scaling` provides a list of available scales. -#' @examples -#' \dontrun{ -#' # Regular plots use continuous linear scale for x-axis -#' plotConfiguration <- PlotConfiguration$new() -#' yAxisDefaultScale(plotConfiguration) -#' -#' # DDI plots use log scale for y-axis -#' ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() -#' yAxisDefaultScale(ddiPlotConfiguration) -#' -#' # Tornado plots use discrete scale for y-axis -#' tornadoPlotConfiguration <- TornadoPlotConfiguration$new() -#' yAxisDefaultScale(tornadoPlotConfiguration) -#' } -#' @keywords internal -yAxisDefaultScale <- function(plotConfiguration) { - if (isOfType(plotConfiguration, c("PKRatioPlotConfiguration", "DDIRatioPlotConfiguration"))) { - return(Scaling$log) - } - if (isOfType(plotConfiguration, c("TornadoPlotConfiguration"))) { - return(Scaling$discrete) - } - return(Scaling$lin) -} #' @title getLogTickLabels #' @description Get ticklabels expressions for log scale plots @@ -238,49 +179,3 @@ getSqrtTickLabels <- function(ticks) { sqrtValues <- ticks^2 return(parse(text = paste("sqrt(", sqrtValues, ")", sep = ""))) } - -#' @title xAxisDefaultExpand -#' @description Return x-axis default expand from a plot configuration -#' @param plotConfiguration A `PlotConfiguration` object -#' @return The default expand. -#' @examples -#' \dontrun{ -#' # Regular plots use continuous linear scale for x-axis -#' plotConfiguration <- PlotConfiguration$new() -#' xAxisDefaultExpand(plotConfiguration) -#' -#' # DDI plots use log scale for x-axis -#' ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() -#' xAxisDefaultExpand(ddiPlotConfiguration) -#' -#' # Boxplots use discrete scale for x-axis -#' boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() -#' xAxisDefaultExpand(boxPlotConfiguration) -#' } -#' @keywords internal -xAxisDefaultExpand <- function(plotConfiguration) { - return(isOfType(plotConfiguration, c("DDIRatioPlotConfiguration"))) -} - -#' @title yAxisDefaultExpand -#' @description Return x-axis default expand from a plot configuration -#' @param plotConfiguration A `PlotConfiguration` object -#' @return The default expand. -#' @examples -#' \dontrun{ -#' # Regular plots use continuous linear scale for x-axis -#' plotConfiguration <- PlotConfiguration$new() -#' yAxisDefaultExpand(plotConfiguration) -#' -#' # DDI plots use log scale for x-axis -#' ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() -#' yAxisDefaultExpand(ddiPlotConfiguration) -#' -#' # Boxplots use discrete scale for x-axis -#' boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() -#' yAxisDefaultExpand(boxPlotConfiguration) -#' } -#' @keywords internal -yAxisDefaultExpand <- function(plotConfiguration) { - return(isOfType(plotConfiguration, c("DDIRatioPlotConfiguration"))) -} diff --git a/man/BoxWhiskerPlotConfiguration.Rd b/man/BoxWhiskerPlotConfiguration.Rd index 754e074c..127c5727 100644 --- a/man/BoxWhiskerPlotConfiguration.Rd +++ b/man/BoxWhiskerPlotConfiguration.Rd @@ -20,6 +20,13 @@ Other PlotConfiguration classes: \section{Super class}{ \code{\link[tlf:PlotConfiguration]{tlf::PlotConfiguration}} -> \code{BoxWhiskerPlotConfiguration} } +\section{Public fields}{ +\if{html}{\out{
}} +\describe{ +\item{\code{defaultXScale}}{Default xAxis scale value when creating a \code{BoxWhiskerPlotConfiguration} object} +} +\if{html}{\out{
}} +} \section{Active bindings}{ \if{html}{\out{
}} \describe{ diff --git a/man/DDIRatioPlotConfiguration.Rd b/man/DDIRatioPlotConfiguration.Rd index b4d6449b..6cebdddf 100644 --- a/man/DDIRatioPlotConfiguration.Rd +++ b/man/DDIRatioPlotConfiguration.Rd @@ -20,6 +20,17 @@ Other PlotConfiguration classes: \section{Super class}{ \code{\link[tlf:PlotConfiguration]{tlf::PlotConfiguration}} -> \code{DDIRatioPlotConfiguration} } +\section{Public fields}{ +\if{html}{\out{
}} +\describe{ +\item{\code{defaultXScale}}{Default xAxis scale value when creating a \code{DDIRatioPlotConfiguration} object} + +\item{\code{defaultYScale}}{Default yAxis scale value when creating a \code{DDIRatioPlotConfiguration} object} + +\item{\code{defaultExpand}}{Default expand value when creating a \code{DDIRatioPlotConfiguration} object} +} +\if{html}{\out{
}} +} \section{Methods}{ \subsection{Public methods}{ \itemize{ diff --git a/man/PKRatioPlotConfiguration.Rd b/man/PKRatioPlotConfiguration.Rd index b46b7fec..a0365e55 100644 --- a/man/PKRatioPlotConfiguration.Rd +++ b/man/PKRatioPlotConfiguration.Rd @@ -20,6 +20,13 @@ Other PlotConfiguration classes: \section{Super class}{ \code{\link[tlf:PlotConfiguration]{tlf::PlotConfiguration}} -> \code{PKRatioPlotConfiguration} } +\section{Public fields}{ +\if{html}{\out{
}} +\describe{ +\item{\code{defaultYScale}}{Default yAxis scale value when creating a \code{PKRatioPlotConfiguration} object} +} +\if{html}{\out{
}} +} \section{Methods}{ \subsection{Public methods}{ \itemize{ diff --git a/man/PlotConfiguration.Rd b/man/PlotConfiguration.Rd index af8fbb84..92c3314e 100644 --- a/man/PlotConfiguration.Rd +++ b/man/PlotConfiguration.Rd @@ -25,6 +25,12 @@ Other PlotConfiguration classes: \if{html}{\out{
}} \describe{ \item{\code{export}}{R6 class \code{ExportConfiguration} defining properties for saving/exporting plota} + +\item{\code{defaultXScale}}{Default xAxis scale value when creating a \code{PlotConfiguration} object} + +\item{\code{defaultYScale}}{Default yAxis scale value when creating a \code{PlotConfiguration} object} + +\item{\code{defaultExpand}}{Default expand value when creating a \code{PlotConfiguration} object} } \if{html}{\out{
}} } diff --git a/man/TornadoPlotConfiguration.Rd b/man/TornadoPlotConfiguration.Rd index 7fefb366..796031b8 100644 --- a/man/TornadoPlotConfiguration.Rd +++ b/man/TornadoPlotConfiguration.Rd @@ -28,6 +28,8 @@ Other PlotConfiguration classes: \item{\code{colorPalette}}{color palette property from \code{ggplot2}} \item{\code{dodge}}{space between the bars/points} + +\item{\code{defaultYScale}}{Default yAxis scale value when creating a \code{TornadoPlotConfiguration} object} } \if{html}{\out{
}} } diff --git a/man/xAxisDefaultExpand.Rd b/man/xAxisDefaultExpand.Rd deleted file mode 100644 index 6892025c..00000000 --- a/man/xAxisDefaultExpand.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utilities-axis.R -\name{xAxisDefaultExpand} -\alias{xAxisDefaultExpand} -\title{xAxisDefaultExpand} -\usage{ -xAxisDefaultExpand(plotConfiguration) -} -\arguments{ -\item{plotConfiguration}{A \code{PlotConfiguration} object} -} -\value{ -The default expand. -} -\description{ -Return x-axis default expand from a plot configuration -} -\examples{ -\dontrun{ -# Regular plots use continuous linear scale for x-axis -plotConfiguration <- PlotConfiguration$new() -xAxisDefaultExpand(plotConfiguration) - -# DDI plots use log scale for x-axis -ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() -xAxisDefaultExpand(ddiPlotConfiguration) - -# Boxplots use discrete scale for x-axis -boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() -xAxisDefaultExpand(boxPlotConfiguration) -} -} -\keyword{internal} diff --git a/man/xAxisDefaultScale.Rd b/man/xAxisDefaultScale.Rd deleted file mode 100644 index de91674e..00000000 --- a/man/xAxisDefaultScale.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utilities-axis.R -\name{xAxisDefaultScale} -\alias{xAxisDefaultScale} -\title{xAxisDefaultScale} -\usage{ -xAxisDefaultScale(plotConfiguration) -} -\arguments{ -\item{plotConfiguration}{A \code{PlotConfiguration} object} -} -\value{ -The default scale. -The enum \code{Scaling} provides a list of available scales. -} -\description{ -Return x-axis default scale from a plot configuration -} -\examples{ -\dontrun{ -# Regular plots use continuous linear scale for x-axis -plotConfiguration <- PlotConfiguration$new() -xAxisDefaultScale(plotConfiguration) - -# DDI plots use log scale for x-axis -ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() -xAxisDefaultScale(ddiPlotConfiguration) - -# Boxplots use discrete scale for x-axis -boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() -xAxisDefaultScale(boxPlotConfiguration) -} -} -\keyword{internal} diff --git a/man/yAxisDefaultExpand.Rd b/man/yAxisDefaultExpand.Rd deleted file mode 100644 index 1b843dcc..00000000 --- a/man/yAxisDefaultExpand.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utilities-axis.R -\name{yAxisDefaultExpand} -\alias{yAxisDefaultExpand} -\title{yAxisDefaultExpand} -\usage{ -yAxisDefaultExpand(plotConfiguration) -} -\arguments{ -\item{plotConfiguration}{A \code{PlotConfiguration} object} -} -\value{ -The default expand. -} -\description{ -Return x-axis default expand from a plot configuration -} -\examples{ -\dontrun{ -# Regular plots use continuous linear scale for x-axis -plotConfiguration <- PlotConfiguration$new() -yAxisDefaultExpand(plotConfiguration) - -# DDI plots use log scale for x-axis -ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() -yAxisDefaultExpand(ddiPlotConfiguration) - -# Boxplots use discrete scale for x-axis -boxPlotConfiguration <- BoxWhiskerPlotConfiguration$new() -yAxisDefaultExpand(boxPlotConfiguration) -} -} -\keyword{internal} diff --git a/man/yAxisDefaultScale.Rd b/man/yAxisDefaultScale.Rd deleted file mode 100644 index 2833aa42..00000000 --- a/man/yAxisDefaultScale.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utilities-axis.R -\name{yAxisDefaultScale} -\alias{yAxisDefaultScale} -\title{yAxisDefaultScale} -\usage{ -yAxisDefaultScale(plotConfiguration) -} -\arguments{ -\item{plotConfiguration}{A \code{PlotConfiguration} object} -} -\value{ -The default scale. -The enum \code{Scaling} provides a list of available scales. -} -\description{ -Return y-axis default scale from a plot configuration -} -\examples{ -\dontrun{ -# Regular plots use continuous linear scale for x-axis -plotConfiguration <- PlotConfiguration$new() -yAxisDefaultScale(plotConfiguration) - -# DDI plots use log scale for y-axis -ddiPlotConfiguration <- DDIRatioPlotConfiguration$new() -yAxisDefaultScale(ddiPlotConfiguration) - -# Tornado plots use discrete scale for y-axis -tornadoPlotConfiguration <- TornadoPlotConfiguration$new() -yAxisDefaultScale(tornadoPlotConfiguration) -} -} -\keyword{internal} From 743166c36e7170dd61d110cf0a8b5848ac8f55a5 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 29 Apr 2022 11:22:07 -0400 Subject: [PATCH 3/3] Remove usage of enum Scaling for constants to prevent build crash --- R/boxwhisker-plotconfiguration.R | 2 +- R/plotconfiguration.R | 12 +++++++----- R/tornado-plotconfiguration.R | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/R/boxwhisker-plotconfiguration.R b/R/boxwhisker-plotconfiguration.R index 04005916..babf089f 100644 --- a/R/boxwhisker-plotconfiguration.R +++ b/R/boxwhisker-plotconfiguration.R @@ -7,7 +7,7 @@ BoxWhiskerPlotConfiguration <- R6::R6Class( inherit = PlotConfiguration, public = list( #' @field defaultXScale Default xAxis scale value when creating a `BoxWhiskerPlotConfiguration` object - defaultXScale = Scaling$discrete, + defaultXScale = "discrete", #' @description Create a new `BoxWhiskerPlotConfiguration` object #' @param outliers logical defining if outliers should be included in boxplot diff --git a/R/plotconfiguration.R b/R/plotconfiguration.R index 17d22abf..b83e378c 100644 --- a/R/plotconfiguration.R +++ b/R/plotconfiguration.R @@ -12,8 +12,10 @@ PlotConfiguration <- R6::R6Class( "PlotConfiguration", public = list( export = NULL, - defaultXScale = Scaling$lin, - defaultYScale = Scaling$lin, + # Caution, helper enum Scaling doesn't work here + # (even using @include to collate and define the variable beforehand) + defaultXScale = "lin", + defaultYScale = "lin", defaultExpand = FALSE, #' @description Create a new `PlotConfiguration` object @@ -291,7 +293,7 @@ PKRatioPlotConfiguration <- R6::R6Class( "PKRatioPlotConfiguration", inherit = PlotConfiguration, public = list( - defaultYScale = Scaling$log + defaultYScale = "log" ) ) @@ -306,8 +308,8 @@ DDIRatioPlotConfiguration <- R6::R6Class( "DDIRatioPlotConfiguration", inherit = PlotConfiguration, public = list( - defaultXScale = Scaling$log, - defaultYScale = Scaling$log, + defaultXScale = "log", + defaultYScale = "log", defaultExpand = TRUE ) ) diff --git a/R/tornado-plotconfiguration.R b/R/tornado-plotconfiguration.R index 0c95f953..61156d39 100644 --- a/R/tornado-plotconfiguration.R +++ b/R/tornado-plotconfiguration.R @@ -13,7 +13,7 @@ TornadoPlotConfiguration <- R6::R6Class( #' @field dodge space between the bars/points dodge = NULL, #' @field defaultYScale Default yAxis scale value when creating a `TornadoPlotConfiguration` object - defaultYScale = Scaling$discrete, + defaultYScale = "discrete", #' @description Create a new `TornadoPlotConfiguration` object #' @param bar logical setting if tornado is uses a bar plot instead of regular points