-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsensitivity-plot-settings.R
183 lines (171 loc) · 7.38 KB
/
sensitivity-plot-settings.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#' @title SensitivityPlotSettings
#' @description R6 class for sensitivity analysis plot settings
#' @export
#' @importFrom ospsuite.utils %||%
SensitivityPlotSettings <- R6::R6Class(
"SensitivityPlotSettings",
public = list(
#' @description
#' Create a `SensitivityPlotSettings` object
#' @param totalSensitivityThreshold cut-off used for plots of the most sensitive parameters
#' @param variableParameterPaths paths that were varied in the sensitivity analysis. If supplied totalSensitivityThreshold = 1, else 0.9.
#' @param maximalParametersPerSensitivityPlot maximalParametersPerSensitivityPlot is the maximal number of parameters to display in a sensitivity plot
#' @param plotConfiguration `PlotConfiguration` object from `tlf` library
#' @param xAxisFontSize Font size of x-axis labels for sensitivity plot
#' @param yAxisFontSize Font size of y-axis labels for sensitivity plot
#' @param xLabel Label of x-axis for sensitivity plot
#' @param yLabel Label of y-axis for sensitivity plot
#' @param maxLinesPerParameter maxLinesPerParameter maximum number of lines allowed per displayed parameters
#' @param maxWidthPerParameter maximum number of characters allowed per lines of displayed parameters
#' @param colorPalette Name of a color palette to be used by `ggplot2::scale_fill_brewer()` for sensitivity plot
#' @return A new `SensitivityPlotSettings` object
initialize = function(totalSensitivityThreshold = NULL,
variableParameterPaths = NULL,
maximalParametersPerSensitivityPlot = NULL,
plotConfiguration = NULL,
xAxisFontSize = 6,
yAxisFontSize = 6,
maxLinesPerParameter = NULL,
maxWidthPerParameter = NULL,
xLabel = "Sensitivity",
yLabel = NULL,
colorPalette = "Spectral") {
validateIsInteger(maximalParametersPerSensitivityPlot, nullAllowed = TRUE)
validateIsInteger(maxLinesPerParameter, nullAllowed = TRUE)
validateIsInteger(maxWidthPerParameter, nullAllowed = TRUE)
validateIsNumeric(xAxisFontSize, nullAllowed = TRUE)
validateIsNumeric(yAxisFontSize, nullAllowed = TRUE)
private$.totalSensitivityThreshold <- getDefaultTotalSensitivityThreshold(
totalSensitivityThreshold = totalSensitivityThreshold,
variableParameterPaths = variableParameterPaths
)
private$.maximalParametersPerSensitivityPlot <- maximalParametersPerSensitivityPlot %||% reEnv$maximalParametersPerSensitivityPlot
private$.plotConfiguration <- plotConfiguration
private$.xAxisFontSize <- xAxisFontSize
private$.yAxisFontSize <- yAxisFontSize
private$.maxLinesPerParameter <- maxLinesPerParameter %||% reEnv$maxLinesPerParameter
# Default line breaks will now be limited to 1/3 of plot width
defaultPlotConfiguration <- tlf::TornadoPlotConfiguration$new(bar = FALSE)
defaultPlotConfiguration$yAxis$font$size <- yAxisFontSize
private$.maxWidthPerParameter <- maxWidthPerParameter %||% getLineBreakWidth(element = "yticklabels", plotConfiguration %||% defaultPlotConfiguration)
private$.xLabel <- xLabel
private$.yLabel <- yLabel
private$.colorPalette <- colorPalette
}
),
active = list(
#' @field totalSensitivityThreshold cut-off used for plots of the most sensitive parameters
totalSensitivityThreshold = function(value) {
if (missing(value)) {
private$.totalSensitivityThreshold
} else {
if (!is.null(value)) {
validateIsInRange("totalSensitivityThreshold", value, 0, 1)
private$.totalSensitivityThreshold <- value
}
}
},
#' @field maximalParametersPerSensitivityPlot is the maximal number of parameters to display in a sensitivity plot
maximalParametersPerSensitivityPlot = function(value) {
if (missing(value)) {
private$.maximalParametersPerSensitivityPlot
} else {
if (!is.null(value)) {
validateIsInteger(value)
private$.maximalParametersPerSensitivityPlot <- value
}
}
},
#' @field plotConfiguration `PlotConfiguration` R6 class object from `tlf` library
plotConfiguration = function(value) {
if (missing(value)) {
private$.plotConfiguration
} else {
validateIsOfType(value, "PlotConfiguration", nullAllowed = TRUE)
private$.plotConfiguration <- value
}
},
#' @field xAxisFontSize for sensitivity plot.
#' This Value will overwrite values defined by plot configuration object
xAxisFontSize = function(value) {
if (missing(value)) {
private$.xAxisFontSize
} else {
validateIsNumeric(object = value, nullAllowed = FALSE)
validateIsPositive(object = value, nullAllowed = FALSE)
private$.xAxisFontSize <- value
}
},
#' @field yAxisFontSize for sensitivity plot.
#' This Value will overwrite values defined by plot configuration object
yAxisFontSize = function(value) {
if (missing(value)) {
private$.yAxisFontSize
} else {
validateIsNumeric(object = value, nullAllowed = FALSE)
validateIsPositive(object = value, nullAllowed = FALSE)
private$.yAxisFontSize <- value
}
},
#' @field xLabel for sensitivity plot.
#' This Value will overwrite values defined by plot configuration object
xLabel = function(value) {
if (missing(value)) {
private$.xLabel
} else {
validateIsString(value, nullAllowed = TRUE)
private$.xLabel <- value
}
},
#' @field yLabel for sensitivity plot.
#' This Value will overwrite values defined by plot configuration object
yLabel = function(value) {
if (missing(value)) {
private$.yLabel
} else {
validateIsString(value, nullAllowed = TRUE)
private$.yLabel <- value
}
},
#' @field colorPalette for sensitivity plot.
#' This Value will overwrite values defined by plot configuration object
colorPalette = function(value) {
if (missing(value)) {
private$.colorPalette
} else {
validateIsOfType(value, c("character", "numeric"), nullAllowed = TRUE)
private$.colorPalette <- value
}
},
#' @field maxLinesPerParameter maximum number of lines allowed per displayed parameters
maxLinesPerParameter = function(value) {
if (missing(value)) {
private$.maxLinesPerParameter
} else {
validateIsInteger(value, nullAllowed = TRUE)
private$.maxLinesPerParameter <- value %||% private$.maxLinesPerParameter
}
},
#' @field maxWidthPerParameter maximum number of characters allowed per lines of displayed parameters
maxWidthPerParameter = function(value) {
if (missing(value)) {
private$.maxWidthPerParameter
} else {
validateIsInteger(value, nullAllowed = TRUE)
private$.maxWidthPerParameter <- value %||% private$.maxWidthPerParameter
}
}
),
private = list(
.totalSensitivityThreshold = NULL,
.maximalParametersPerSensitivityPlot = NULL,
.plotConfiguration = NULL,
.xAxisFontSize = NULL,
.yAxisFontSize = NULL,
.maxLinesPerParameter = NULL,
.maxWidthPerParameter = NULL,
.xLabel = NULL,
.yLabel = NULL,
.colorPalette = NULL
)
)