Skip to content

Commit

Permalink
Fixes #966 population sensitivity plots updated (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
pchelle authored Jan 12, 2023
1 parent f169e5f commit 6b14b64
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/sensitivity-plot-settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SensitivityPlotSettings <- R6::R6Class(
private$.yAxisFontSize <- yAxisFontSize
private$.maxLinesPerParameter <- maxLinesPerParameter %||% reEnv$maxLinesPerParameter
# Default line breaks will now be limited to 1/3 of plot width
defaultPlotConfiguration <- tlf::PlotConfiguration$new()
defaultPlotConfiguration <- tlf::TornadoPlotConfiguration$new(bar = FALSE)
defaultPlotConfiguration$yAxis$font$size <- yAxisFontSize
private$.maxWidthPerParameter <- maxWidthPerParameter %||% getLineBreakWidth(element = "yticklabels", plotConfiguration %||% defaultPlotConfiguration)
private$.xLabel <- xLabel
Expand Down
31 changes: 22 additions & 9 deletions R/utilities-sensitivity-analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,12 @@ plotMeanSensitivity <- function(structureSet, settings) {
sensitivityPlot <- tlf::plotTornado(
data = sensitivityData,
dataMapping = sensitivityMapping,
plotConfiguration = sensitivityPlotConfiguration
plotConfiguration = sensitivityPlotConfiguration,
bar = TRUE
)
# Remove legend which is redundant from y axis
sensitivityPlot <- tlf::setLegendPosition(sensitivityPlot, position = tlf::LegendPositions$none)
sensitivityPlot <- setQuadraticDimension(sensitivityPlot, plotConfiguration = settings$plotConfiguration)

pkParameterCaption <- pkParameter$displayName %||% pkParameter$pkParameter

Expand Down Expand Up @@ -812,16 +814,27 @@ plotPopulationSensitivity <- function(structureSets,
tornadoPlot <- tlf::plotTornado(
data = selectedSensitivityData,
dataMapping = sensitivityMapping,
plotConfiguration = sensitivityPlotConfiguration
plotConfiguration = sensitivityPlotConfiguration,
# tlf default option is current TRUE
# overwriting the plotConfiguration object
bar = FALSE
)
# Legends currently left aligned. This option may be changed on later version and use reEnv instead
tornadoPlot <- tlf::setLegendPosition(tornadoPlot, position = tlf::LegendPositions$outsideTopLeft)
# Legend titles are usually set blanks by tlf,
# ggplot2 theme with an element_text is needed to print descriptor and quantiles
# Right aligning to prevent cropping of legend title
tornadoPlot <- tlf::setLegendPosition(tornadoPlot, position = tlf::LegendPositions$outsideTopRight)
# In tlf, Legend titles are the same between mappings
# Needs to use ggplot2 directly
tornadoPlot <- tornadoPlot +
ggplot2::theme(legend.title = sensitivityPlotConfiguration$legend$font$createPlotFont()) +
ggplot2::labs(color = "Individual Percentile", shape = translateDescriptor(simulationSetDescriptor))

ggplot2::guides(
color = ggplot2::guide_legend(
title = "Individual Percentile",
title.theme = sensitivityPlotConfiguration$legend$font$createPlotFont()
),
shape = ggplot2::guide_legend(
title = translateDescriptor(simulationSetDescriptor),
title.theme = sensitivityPlotConfiguration$legend$font$createPlotFont()
)
)
tornadoPlot <- setQuadraticDimension(tornadoPlot, plotConfiguration = settings$plotConfiguration)

resultID <- defaultFileNames$resultID(length(sensitivityResults) + 1, "sensitivity", selectedPKParameter)
sensitivityResults[[resultID]] <- saveTaskResults(
Expand Down

0 comments on commit 6b14b64

Please sign in to comment.