forked from Open-Systems-Pharmacology/TLF-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
… observed and simulated time profiles (Open-Systems-Pharmacology#393)
- Loading branch information
Showing
19 changed files
with
437 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#' @title plotObservedTimeProfile | ||
#' @description | ||
#' Producing Time Profile plots for observed data | ||
#' | ||
#' @inheritParams addScatter | ||
#' @param dataMapping | ||
#' An `ObservedDataMapping` object mapping `x`, `y`, `ymin`, `ymax` and aesthetic groups to their variable names of `observedData`. | ||
#' @param plotConfiguration | ||
#' An optional `TimeProfilePlotConfiguration` object defining labels, grid, background and watermark. | ||
#' @return A `ggplot` object | ||
#' | ||
#' @export | ||
#' @family molecule plots | ||
#' @examples | ||
#' # Produce a Time profile plot with observed data | ||
#' obsData <- data.frame(x = c(1, 2, 1, 2, 3), y = c(5, 0.2, 2, 3, 4)) | ||
#' plotObservedTimeProfile( | ||
#' data = obsData, | ||
#' dataMapping = ObservedDataMapping$new(x = "x", y = "y") | ||
#' ) | ||
plotObservedTimeProfile <- function(data = NULL, | ||
metaData = NULL, | ||
dataMapping = NULL, | ||
plotConfiguration = NULL, | ||
plotObject = NULL) { | ||
#----- Validation and formatting of input arguments ----- | ||
validateIsNotEmpty(data) | ||
validateIsOfType(data, "data.frame") | ||
dataMapping <- .setDataMapping(dataMapping, ObservedDataMapping, data) | ||
plotConfiguration <- .setPlotConfiguration( | ||
plotConfiguration, TimeProfilePlotConfiguration, | ||
data, metaData, dataMapping | ||
) | ||
plotObject <- .setPlotObject(plotObject, plotConfiguration) | ||
|
||
mapData <- dataMapping$checkMapData(data) | ||
mapLabels <- .getAesStringMapping(dataMapping) | ||
|
||
#----- Build layers of molecule plot ----- | ||
# 1- Error bars if available | ||
if (!any(isEmpty(dataMapping$ymin), isEmpty(dataMapping$ymax))) { | ||
plotObject <- .addErrorbarLayer( | ||
plotObject, | ||
data = mapData, | ||
mapLabels = mapLabels | ||
) | ||
} | ||
# 2- Scatter points | ||
plotObject <- .addScatterLayer( | ||
plotObject, | ||
data = mapData, | ||
mapLabels = mapLabels | ||
) | ||
|
||
#----- Update properties using ggplot2::scale functions ----- | ||
plotObject <- .updateAesProperties( | ||
plotObject, | ||
plotConfigurationProperty = "points", | ||
propertyNames = c("color", "shape"), | ||
data = mapData, | ||
mapLabels = mapLabels | ||
) | ||
plotObject <- .updateAxes(plotObject) | ||
return(plotObject) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#' @title plotSimulatedTimeProfile | ||
#' @description | ||
#' Producing Time Profile plots | ||
#' | ||
#' @inheritParams addScatter | ||
#' @param dataMapping | ||
#' A `TimeProfileDataMapping` object mapping `x`, `y`, `ymin`, `ymax` and aesthetic groups to their variable names of `data`. | ||
#' @param plotConfiguration | ||
#' An optional `TimeProfilePlotConfiguration` object defining labels, grid, background and watermark. | ||
#' @return A `ggplot` object | ||
#' | ||
#' @export | ||
#' @family molecule plots | ||
#' @examples | ||
#' # Produce a Time profile plot with simulated data | ||
#' simTime <- seq(1, 10, 0.1) | ||
#' simData <- data.frame( | ||
#' x = simTime, | ||
#' y = 10 * exp(-simTime), | ||
#' ymin = 8 * exp(-simTime), | ||
#' ymax = 12 * exp(-simTime) | ||
#' ) | ||
#' | ||
#' plotSimulatedTimeProfile( | ||
#' data = simData, | ||
#' dataMapping = TimeProfileDataMapping$new(x = "x", y = "y", ymin = "ymin", ymax = "ymax") | ||
#' ) | ||
plotSimulatedTimeProfile <- function(data = NULL, | ||
metaData = NULL, | ||
dataMapping = NULL, | ||
plotConfiguration = NULL, | ||
plotObject = NULL) { | ||
#----- Validation and formatting of input arguments ----- | ||
validateIsNotEmpty(data) | ||
validateIsOfType(data, "data.frame") | ||
dataMapping <- .setDataMapping(dataMapping, TimeProfileDataMapping, data) | ||
plotConfiguration <- .setPlotConfiguration( | ||
plotConfiguration, TimeProfilePlotConfiguration, | ||
data, metaData, dataMapping | ||
) | ||
plotObject <- .setPlotObject(plotObject, plotConfiguration) | ||
|
||
mapData <- dataMapping$checkMapData(data) | ||
mapLabels <- .getAesStringMapping(dataMapping) | ||
|
||
#----- Build layers of molecule plot ----- | ||
# 1- Ribbons if available | ||
if (!any(isEmpty(dataMapping$ymin), isEmpty(dataMapping$ymax))) { | ||
aestheticValues <- .getAestheticValuesFromConfiguration( | ||
n = 1, | ||
position = 0, | ||
plotConfigurationProperty = plotObject$plotConfiguration$ribbons, | ||
propertyNames = c("alpha") | ||
) | ||
plotObject <- plotObject + | ||
ggplot2::geom_ribbon( | ||
data = mapData, | ||
mapping = ggplot2::aes_string( | ||
x = mapLabels$x, | ||
ymin = mapLabels$ymin, | ||
ymax = mapLabels$ymax, | ||
fill = mapLabels$fill, | ||
group = mapLabels$linetype | ||
), | ||
alpha = aestheticValues$alpha, | ||
na.rm = TRUE, | ||
show.legend = TRUE | ||
) | ||
} | ||
|
||
# 2- Lines | ||
if (!isEmpty(dataMapping$y)) { | ||
aestheticValues <- .getAestheticValuesFromConfiguration( | ||
n = 1, | ||
position = 0, | ||
plotConfigurationProperty = plotObject$plotConfiguration$lines, | ||
propertyNames = c("alpha", "size") | ||
) | ||
plotObject <- plotObject + | ||
ggplot2::geom_path( | ||
data = mapData, | ||
mapping = ggplot2::aes_string( | ||
x = mapLabels$x, | ||
y = mapLabels$y, | ||
color = mapLabels$color, | ||
linetype = mapLabels$linetype | ||
), | ||
size = aestheticValues$size, | ||
alpha = aestheticValues$alpha, | ||
na.rm = TRUE, | ||
show.legend = TRUE, | ||
) | ||
} | ||
|
||
#----- Update properties using ggplot2::scale functions ----- | ||
plotObject <- .updateAesProperties( | ||
plotObject, | ||
plotConfigurationProperty = "ribbons", | ||
propertyNames = "fill", | ||
data = mapData, | ||
mapLabels = mapLabels | ||
) | ||
plotObject <- .updateAesProperties( | ||
plotObject, | ||
plotConfigurationProperty = "lines", | ||
propertyNames = c("color", "linetype"), | ||
data = mapData, | ||
mapLabels = mapLabels | ||
) | ||
plotObject <- .updateAxes(plotObject) | ||
return(plotObject) | ||
} |
Oops, something went wrong.