From a85a3717556985d094d9201dbd87b598592452ef Mon Sep 17 00:00:00 2001 From: Mohamed Yusuf Date: Wed, 11 Sep 2024 14:35:35 +0300 Subject: [PATCH] Add functionality to autoscale nanoplot --- R/validate_data.R | 19 +++++++++++++++---- man/create_gt_table.Rd | 6 +++++- man/validate_afro.Rd | 4 ++++ man/validate_polis.Rd | 4 ++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/R/validate_data.R b/R/validate_data.R index 1b1d2a2..f766dd1 100644 --- a/R/validate_data.R +++ b/R/validate_data.R @@ -1468,6 +1468,8 @@ create_summary_by_group <- function(data, group_var, id_col, geo_name_cols, #' Default is TRUE. #' @param row_start An integer indicating the starting row for data color #' formatting. Default is 6. +#' @param autoscale_nanoplot Logical. Whether to autoscale the nanoplot. +#' Default is FALSE. #' #' @return A GT table object with formatted data quality summary. #' @@ -1490,7 +1492,8 @@ create_summary_by_group <- function(data, group_var, id_col, geo_name_cols, #' @export create_gt_table <- function(summary_data, title = "Summary of POLIS Data Quality Checks", - add_nanoplot = TRUE, row_start = 6) { + add_nanoplot = TRUE, row_start = 6, + autoscale_nanoplot = FALSE) { # Conditional loading for packages required_packages <- c("scales", "gt", "glue") @@ -1561,7 +1564,7 @@ create_gt_table <- function(summary_data, columns = -c(1, 2), new_col_name = "nanoplot", new_col_label = gt::md("**Quality Trend**"), - autohide = FALSE, + autohide = FALSE, autoscale = autoscale_nanoplot, options = gt::nanoplot_options( data_bar_stroke_width = 10, vertical_guide_stroke_width = 51 @@ -1608,6 +1611,8 @@ create_gt_table <- function(summary_data, #' Default is 1400. #' @param vwidth Integer. The width of the output image in pixels. Default #' is 1550. +#' @param autoscale_nanoplot Logical. Whether to autoscale the nanoplot. +#' Default is FALSE. #' @param ... Additional arguments passed to internal functions. #' #' @return A list containing two elements: @@ -1654,6 +1659,7 @@ validate_polis <- function(data, type = "AFP", decreasing = FALSE, plots_path = NULL, polis_version = "2.37.1", + autoscale_nanoplot = FALSE, custom_title = NULL, save_output = FALSE, vheight = 1400, vwidth = 1550, ...) { # Conditional loading for packages @@ -1800,7 +1806,8 @@ validate_polis <- function(data, type = "AFP", summary$summary_table |> dplyr::filter( Column != "Total Null Columns" ), - title = title + title = title, + autoscale_nanoplot = autoscale_nanoplot ) if (save_output) { @@ -1858,6 +1865,8 @@ validate_polis <- function(data, type = "AFP", #' Default is 1400. #' @param vwidth Integer. The width of the output image in pixels. Default #' is 1550. +#' @param autoscale_nanoplot Logical. Whether to autoscale the nanoplot. +#' Default is FALSE. #' @param ... Additional arguments passed to internal functions. #' #' @return A list containing two elements: @@ -1903,7 +1912,8 @@ validate_afro <- function(data, type = "AFP", decreasing = FALSE, plots_path = NULL, custom_title = NULL, save_output = FALSE, - vheight = 1400, vwidth = 1550, ...) { + vheight = 1400, vwidth = 1550, + autoscale_nanoplot = FALSE, ...) { # Conditional loading for packages required_packages <- c( "scales", "zoo", "gt", "glue", "webshot" @@ -2051,6 +2061,7 @@ validate_afro <- function(data, type = "AFP", summary$summary_table |> dplyr::filter( Column != "Total Null Columns" ), + autoscale_nanoplot = autoscale_nanoplot, title = title ) diff --git a/man/create_gt_table.Rd b/man/create_gt_table.Rd index d125945..cfd7aa5 100644 --- a/man/create_gt_table.Rd +++ b/man/create_gt_table.Rd @@ -8,7 +8,8 @@ create_gt_table( summary_data, title = "Summary of POLIS Data Quality Checks", add_nanoplot = TRUE, - row_start = 6 + row_start = 6, + autoscale_nanoplot = FALSE ) } \arguments{ @@ -23,6 +24,9 @@ Default is TRUE.} \item{row_start}{An integer indicating the starting row for data color formatting. Default is 6.} + +\item{autoscale_nanoplot}{Logical. Whether to autoscale the nanoplot. +Default is FALSE.} } \value{ A GT table object with formatted data quality summary. diff --git a/man/validate_afro.Rd b/man/validate_afro.Rd index cf0a04a..2fd7142 100644 --- a/man/validate_afro.Rd +++ b/man/validate_afro.Rd @@ -21,6 +21,7 @@ validate_afro( save_output = FALSE, vheight = 1400, vwidth = 1550, + autoscale_nanoplot = FALSE, ... ) } @@ -70,6 +71,9 @@ Default is 1400.} \item{vwidth}{Integer. The width of the output image in pixels. Default is 1550.} +\item{autoscale_nanoplot}{Logical. Whether to autoscale the nanoplot. +Default is FALSE.} + \item{...}{Additional arguments passed to internal functions.} } \value{ diff --git a/man/validate_polis.Rd b/man/validate_polis.Rd index 9361502..5eb5a8b 100644 --- a/man/validate_polis.Rd +++ b/man/validate_polis.Rd @@ -18,6 +18,7 @@ validate_polis( decreasing = FALSE, plots_path = NULL, polis_version = "2.37.1", + autoscale_nanoplot = FALSE, custom_title = NULL, save_output = FALSE, vheight = 1400, @@ -63,6 +64,9 @@ save_output is TRUE.} \item{polis_version}{Character string. The version of POLIS being used. Default is "2.37.1".} +\item{autoscale_nanoplot}{Logical. Whether to autoscale the nanoplot. +Default is FALSE.} + \item{custom_title}{Optional. A custom title for the output table.} \item{save_output}{Logical. Whether to save the output as HTML and PNG.