Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1210 x ticks and labels are aligned #1214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion R/utilities-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,9 @@ getBoxWhiskerPlotConfiguration <- function(plotScale = "log",
)
# Remove xlabel
plotConfiguration$labels$xlabel$text <- NULL
# Default angle for xticklabels is 45 degrees
# Default angle for x-ticklabels is 45 degrees right aligned
plotConfiguration$xAxis$font$angle <- 45
plotConfiguration$xAxis$font$align <- tlf::Alignments$right
# No need for legend for boxplots
plotConfiguration$legend$position <- tlf::LegendPositions$none
# Color groups
Expand All @@ -739,6 +740,45 @@ getBoxWhiskerPlotConfiguration <- function(plotScale = "log",
return(plotConfiguration)
}

#' @title alignXTicks
#' @description
#' Use the `plotConfiguration` of a `plotObject`
#' to check and perform vertical alignment of x-axis tick labels
#' @param plotObject A `ggplot` object
#' @return A `ggplot` object
#' @keywords internal
#' @import ggplot2
alignXTicks <- function(plotObject) {
# vertical alignment required only for 45 degrees right aligned x-axis labels
requireAlignment <- all(
isIncluded(
plotObject$plotConfiguration$xAxis$font$align,
tlf::Alignments$right
),
plotObject$plotConfiguration$xAxis$font$angle %in% 45
)
if (!requireAlignment) {
return(plotObject)
}
xAxisFont <- plotObject$plotConfiguration$xAxis$font
plotObject <- plotObject + ggplot2::theme(
axis.text.x = ggplot2::element_text(
colour = xAxisFont$color,
size = xAxisFont$size,
face = xAxisFont$fontFace,
family = tlf:::.checkPlotFontFamily(xAxisFont$fontFamily),
hjust = switch(xAxisFont$align,
left = 0,
center = 0.5,
right = 1
),
vjust = 1
)
)
return(plotObject)
}


#' @title getColorFromOutputGroup
#' @description Get the appropriate colors from an output group
#' @param group A data.frame mapping properties to output groups
Expand Down
12 changes: 6 additions & 6 deletions R/utilities-pop-pk-parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ plotPopulationPKParameters <- function(structureSets,
resultID <- defaultFileNames$resultID(length(pkParametersResults) + 1, "pk_parameters", pkParameter$pkParameter, "log")
pkParametersResults[[resultID]] <- saveTaskResults(
id = resultID,
plot = pkParameterBoxplotLog,
plot = alignXTicks(pkParameterBoxplotLog),
plotCaption = captions$plotPKParameters$boxplot(
parameterCaption,
output$displayName,
Expand All @@ -179,7 +179,7 @@ plotPopulationPKParameters <- function(structureSets,
resultID <- defaultFileNames$resultID(length(pkParametersResults) + 1, "pk_parameters", pkParameter$pkParameter)
pkParametersResults[[resultID]] <- saveTaskResults(
id = resultID,
plot = pkParameterBoxplot,
plot = alignXTicks(pkParameterBoxplot),
plotCaption = captions$plotPKParameters$boxplot(
parameterCaption,
output$displayName,
Expand Down Expand Up @@ -404,7 +404,7 @@ plotPopulationPKParameters <- function(structureSets,
resultID <- defaultFileNames$resultID(length(pkParametersResults) + 1, "pk_parameters", pkParameter$pkParameter, "log")
pkParametersResults[[resultID]] <- saveTaskResults(
id = resultID,
plot = boxplotPKRatiosLog,
plot = alignXTicks(boxplotPKRatiosLog),
plotCaption = captions$plotPKParameters$relativeChangePlot(
parameterCaption,
output$displayName,
Expand All @@ -420,7 +420,7 @@ plotPopulationPKParameters <- function(structureSets,
resultID <- defaultFileNames$resultID(length(pkParametersResults) + 1, "pk_parameters", pkParameter$pkParameter)
pkParametersResults[[resultID]] <- saveTaskResults(
id = resultID,
plot = boxplotPKRatios,
plot = alignXTicks(boxplotPKRatios),
plotCaption = captions$plotPKParameters$relativeChangePlot(
parameterCaption,
output$displayName,
Expand Down Expand Up @@ -492,7 +492,7 @@ plotPopulationPKParameters <- function(structureSets,
resultID <- defaultFileNames$resultID(length(pkParametersResults) + 1, "pk_ratios", pkParameter$pkParameter, "log")
pkParametersResults[[resultID]] <- saveTaskResults(
id = resultID,
plot = boxplotPKRatiosLog,
plot = alignXTicks(boxplotPKRatiosLog),
plotCaption = captions$plotPKParameters$ratioPlot(
parameterCaption,
output$displayName,
Expand All @@ -508,7 +508,7 @@ plotPopulationPKParameters <- function(structureSets,
resultID <- defaultFileNames$resultID(length(pkParametersResults) + 1, "pk_ratios", pkParameter$pkParameter)
pkParametersResults[[resultID]] <- saveTaskResults(
id = resultID,
plot = boxplotPKRatios,
plot = alignXTicks(boxplotPKRatios),
plotCaption = captions$plotPKParameters$ratioPlot(
parameterCaption,
output$displayName,
Expand Down
19 changes: 19 additions & 0 deletions man/alignXTicks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading