From 9ace34a7032298d44a84a69d108fdcb519dea44d Mon Sep 17 00:00:00 2001 From: kartikeya kirar Date: Tue, 4 Jun 2024 14:29:07 +0530 Subject: [PATCH] update goshawk v0.1.17 changes (#277) part of : https://github.com/insightsengineering/goshawk/issues/243 Exposed the `dot_size` argument in `th_lineplot `and `th_spaghettiplot` --- DESCRIPTION | 2 +- R/tm_g_gh_lineplot.R | 33 ++++++++++++++++++++++++-- R/tm_g_gh_spaghettiplot.R | 46 +++++++++++++++++++++++++++++++----- README.md | 1 - man/tm_g_gh_lineplot.Rd | 3 +++ man/tm_g_gh_spaghettiplot.Rd | 3 +++ vignettes/teal-goshawk.Rmd | 4 ++-- 7 files changed, 80 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c43fe246..d24be87f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ URL: https://insightsengineering.github.io/teal.goshawk/, https://github.com/insightsengineering/teal.goshawk/ BugReports: https://github.com/insightsengineering/teal.goshawk/issues Depends: - goshawk (>= 0.1.15.9007), + goshawk (>= 0.1.17), R (>= 3.6), shiny (>= 1.6.0), teal (>= 0.14.0.9027), diff --git a/R/tm_g_gh_lineplot.R b/R/tm_g_gh_lineplot.R index 81415892..afb65fea 100644 --- a/R/tm_g_gh_lineplot.R +++ b/R/tm_g_gh_lineplot.R @@ -41,6 +41,7 @@ #' @param count_threshold minimum count of observations (as listed in the output table) to plot #' nodes on the graph #' @param table_font_size controls the font size of values in the table +#' @param dot_size plot dot size. #' @param plot_relative_height_value numeric value between 500 and 5000 for controlling the starting value #' of the relative plot height slider #' @author Wenyi Liu (luiw2) wenyi.liu@roche.com @@ -155,13 +156,26 @@ tm_g_gh_lineplot <- function(label, post_output = NULL, count_threshold = 0, table_font_size = c(12, 4, 20), + dot_size = c(2, 1, 12), plot_relative_height_value = 1000) { message("Initializing tm_g_gh_lineplot") + # Validate string inputs + checkmate::assert_string(label) + checkmate::assert_string(dataname) + checkmate::assert_string(param_var) + checkmate::assert_string(param_var_label) + checkmate::assert_string(stat) + + # Validate choices_selected class inputs checkmate::assert_class(param, "choices_selected") checkmate::assert_class(xaxis_var, "choices_selected") checkmate::assert_class(yaxis_var, "choices_selected") checkmate::assert_class(trt_group, "choices_selected") + + # Validate flag inputs checkmate::assert_flag(rotate_xlab) + + # Validate numeric vector inputs checkmate::assert_numeric(plot_height, len = 3, any.missing = FALSE, finite = TRUE) checkmate::assert_numeric(plot_height[1], lower = plot_height[2], upper = plot_height[3], .var.name = "plot_height") checkmate::assert_numeric(plot_width, len = 3, any.missing = FALSE, null.ok = TRUE, finite = TRUE) @@ -170,16 +184,23 @@ tm_g_gh_lineplot <- function(label, lower = plot_width[2], upper = plot_width[3], null.ok = TRUE, .var.name = "plot_width" ) checkmate::assert_numeric(table_font_size, len = 3, any.missing = FALSE, null.ok = TRUE, finite = TRUE) + checkmate::assert_numeric(dot_size, len = 3) checkmate::assert_numeric( table_font_size[1], lower = table_font_size[2], upper = table_font_size[3], null.ok = TRUE, .var.name = "table_font_size" ) - checkmate::assert_number(plot_relative_height_value, lower = 500, upper = 5000) - checkmate::assert_number(count_threshold) + + # Validate color manual if provided + checkmate::assert_character(color_manual, null.ok = TRUE) + checkmate::assert_character(hline_arb_color) + checkmate::assert_character(hline_arb_label) + + # Validate line arguments validate_line_arb_arg(hline_arb, hline_arb_color, hline_arb_label) + args <- as.list(environment()) module( @@ -284,6 +305,12 @@ ui_lineplot <- function(id, ...) { "Font Size", a$plot_font_size, ticks = FALSE + ), + teal.widgets::optionalSliderInputValMinMax( + ns("dot_size"), + "Dot Size", + a$dot_size, + ticks = FALSE ) ), teal.widgets::panel_item( @@ -647,6 +674,7 @@ srv_lineplot <- function(id, # nolint start ylim <- yrange_slider$state()$value plot_font_size <- input$plot_font_size + dot_size <- input$dot_size dodge <- input$dodge rotate_xlab <- input$rotate_xlab count_threshold <- `if`(is.na(as.numeric(input$count_threshold)), 0, as.numeric(input$count_threshold)) @@ -730,6 +758,7 @@ srv_lineplot <- function(id, rotate_xlab = .(rotate_xlab), plot_height = .(relative_height), # in g_lineplot this is relative height of plot to table plot_font_size = .(plot_font_size), + dot_size = .(dot_size), dodge = .(dodge), count_threshold = .(count_threshold), table_font_size = .(table_font_size), diff --git a/R/tm_g_gh_spaghettiplot.R b/R/tm_g_gh_spaghettiplot.R index ab5a0d94..afcf9152 100644 --- a/R/tm_g_gh_spaghettiplot.R +++ b/R/tm_g_gh_spaghettiplot.R @@ -35,6 +35,7 @@ #' @param plot_height controls plot height. #' @param plot_width optional, controls plot width. #' @param font_size control font size for title, `x-axis`, `y-axis` and legend font. +#' @param dot_size plot dot size. #' @param group_stats control group mean or median overlay. #' @param hline_arb numeric vector of at most 2 values identifying intercepts for arbitrary horizontal lines. #' @param hline_arb_color a character vector of at most length of \code{hline_arb}. @@ -181,6 +182,7 @@ tm_g_gh_spaghettiplot <- function(label, plot_height = c(600, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), + dot_size = c(2, 1, 12), hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", @@ -190,20 +192,49 @@ tm_g_gh_spaghettiplot <- function(label, pre_output = NULL, post_output = NULL) { message("Initializing tm_g_gh_spaghettiplot") + + # Validate string inputs + checkmate::assert_string(label) + checkmate::assert_string(dataname) + checkmate::assert_string(param_var) + checkmate::assert_string(param_var_label) + checkmate::assert_string(idvar) + checkmate::assert_string(group_stats) + + # Validate choices_selected class inputs checkmate::assert_class(param, "choices_selected") checkmate::assert_class(xaxis_var, "choices_selected") checkmate::assert_class(yaxis_var, "choices_selected") checkmate::assert_class(trt_group, "choices_selected") - validate_line_arb_arg(hline_arb, hline_arb_color, hline_arb_label) - validate_line_vars_arg(hline_vars, hline_vars_colors, hline_vars_labels) + + # Validate flag inputs + checkmate::assert_flag(rotate_xlab) + checkmate::assert_flag(free_x) + + # Validate numeric vector inputs checkmate::assert_numeric(plot_height, len = 3, any.missing = FALSE, finite = TRUE) checkmate::assert_numeric(plot_height[1], lower = plot_height[2], upper = plot_height[3], .var.name = "plot_height") checkmate::assert_numeric(plot_width, len = 3, any.missing = FALSE, null.ok = TRUE, finite = TRUE) - checkmate::assert_numeric(plot_width[1], - lower = plot_width[2], upper = plot_width[3], null.ok = TRUE, - .var.name = "plot_width" + checkmate::assert_numeric( + plot_width[1], + lower = plot_width[2], upper = plot_width[3], + null.ok = TRUE, .var.name = "plot_width" ) - checkmate::assert_flag(free_x) + checkmate::assert_numeric(font_size, len = 3, any.missing = FALSE, finite = TRUE) + checkmate::assert_numeric(dot_size, len = 3, any.missing = FALSE, finite = TRUE) + + # Validate color manual if provided + checkmate::assert_character(man_color, null.ok = TRUE) + checkmate::assert_character(color_comb, null.ok = TRUE) + checkmate::assert_character(hline_arb_color) + checkmate::assert_character(hline_arb_label) + + # Validate facet columns + checkmate::assert_int(facet_ncol, lower = 1) + + # Validate line arguments + validate_line_arb_arg(hline_arb, hline_arb_color, hline_arb_label) + validate_line_vars_arg(hline_vars, hline_vars_colors, hline_vars_labels) args <- as.list(environment()) @@ -298,6 +329,7 @@ g_ui_spaghettiplot <- function(id, ...) { checkboxInput(ns("free_x"), "Free X-Axis Scales", a$free_x), checkboxInput(ns("rotate_xlab"), "Rotate X-Axis Label", a$rotate_xlab), teal.widgets::optionalSliderInputValMinMax(ns("font_size"), "Font Size", a$font_size, ticks = FALSE), + teal.widgets::optionalSliderInputValMinMax(ns("dot_size"), "Dot Size", a$dot_size, ticks = FALSE), teal.widgets::optionalSliderInputValMinMax( ns("alpha"), "Line Alpha", @@ -408,6 +440,7 @@ srv_g_spaghettiplot <- function(id, hline_arb_color <- horizontal_line()$line_arb_color group_stats <- input$group_stats font_size <- input$font_size + dot_size <- input$dot_size alpha <- input$alpha validate(need(input$trt_group, "Please select a treatment variable")) trt_group <- input$trt_group @@ -473,6 +506,7 @@ srv_g_spaghettiplot <- function(id, xlabel = xlabel, rotate_xlab = .(rotate_xlab), font_size = .(font_size), + dot_size = .(dot_size), alpha = .(alpha), group_stats = .(group_stats), hline_vars = .(hline_vars), diff --git a/README.md b/README.md index 76f82bb7..b69aebbf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # teal.goshawk -[![Check 🛠](https://github.com/insightsengineering/teal.goshawk/actions/workflows/check.yaml/badge.svg)](https://insightsengineering.github.io/teal.goshawk/main/unit-test-report/) [![Docs 📚](https://github.com/insightsengineering/teal.goshawk/actions/workflows/docs.yaml/badge.svg)](https://insightsengineering.github.io/teal.goshawk/) [![Code Coverage 📔](https://raw.githubusercontent.com/insightsengineering/teal.goshawk/_xml_coverage_reports/data/main/badge.svg)](https://insightsengineering.github.io/teal.goshawk/main/coverage-report/) diff --git a/man/tm_g_gh_lineplot.Rd b/man/tm_g_gh_lineplot.Rd index 39155228..881bc6df 100644 --- a/man/tm_g_gh_lineplot.Rd +++ b/man/tm_g_gh_lineplot.Rd @@ -35,6 +35,7 @@ tm_g_gh_lineplot( post_output = NULL, count_threshold = 0, table_font_size = c(12, 4, 20), + dot_size = c(2, 1, 12), plot_relative_height_value = 1000 ) } @@ -110,6 +111,8 @@ nodes on the graph} \item{table_font_size}{controls the font size of values in the table} +\item{dot_size}{plot dot size.} + \item{plot_relative_height_value}{numeric value between 500 and 5000 for controlling the starting value of the relative plot height slider} } diff --git a/man/tm_g_gh_spaghettiplot.Rd b/man/tm_g_gh_spaghettiplot.Rd index 00bbeef5..27a4bdf0 100644 --- a/man/tm_g_gh_spaghettiplot.Rd +++ b/man/tm_g_gh_spaghettiplot.Rd @@ -28,6 +28,7 @@ tm_g_gh_spaghettiplot( plot_height = c(600, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), + dot_size = c(2, 1, 12), hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", @@ -95,6 +96,8 @@ label of \code{x-axis} tick values. Default value is \code{waive()}.} \item{font_size}{control font size for title, \code{x-axis}, \code{y-axis} and legend font.} +\item{dot_size}{plot dot size.} + \item{hline_arb}{numeric vector of at most 2 values identifying intercepts for arbitrary horizontal lines.} \item{hline_arb_color}{a character vector of at most length of \code{hline_arb}. diff --git a/vignettes/teal-goshawk.Rmd b/vignettes/teal-goshawk.Rmd index 56fd8e57..5b881445 100644 --- a/vignettes/teal-goshawk.Rmd +++ b/vignettes/teal-goshawk.Rmd @@ -22,7 +22,7 @@ standards. `teal.goshawk` modules can be used with data other than `ADaM` standa features of the package will likely not be applicable. The concepts presented here require knowledge about the core features of `teal`, specifically on how to launch a `teal` -application and how to pass data into it. Therefore, it is highly recommended to refer to the [`README`](https://insightsengineering.github.io/teal/) file and the introductory [`vignette`](https://insightsengineering.github.io/teal/latest-tag/articles/teal.html) of the `teal` package. +application and how to pass data into it. Therefore, it is highly recommended to refer to the [`README`](https://insightsengineering.github.io/teal/latest-tag/) file and the introductory [`vignette`](https://insightsengineering.github.io/teal/latest-tag/articles/index.html) of the `teal` package. ### Main features @@ -108,4 +108,4 @@ Refer to the [Get Started](https://insightsengineering.github.io/teal.modules.cl section of the teal.modules.clinical package that provides additional detail on `teal` concepts as applied in another simple app example. -Please see additional information under [Articles](https://insightsengineering.github.io/teal.goshawk/latest-tag/articles) for data expectations, requirements and pre/post-processing rationale +Please see additional information under [Articles](https://insightsengineering.github.io/teal.goshawk/latest-tag/articles/index.html) for data expectations, requirements and pre/post-processing rationale