From 04eadf7e3c1468743cbac706d16889850282573a Mon Sep 17 00:00:00 2001 From: chauhaje Date: Wed, 18 Mar 2026 20:49:31 -0400 Subject: [PATCH 1/5] added option to format mean value and also adding vignette file to test the function. testing-format-statistics.Rmd file can be deleted after test --- vignettes/testing-format-statistics.Rmd | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 vignettes/testing-format-statistics.Rmd diff --git a/vignettes/testing-format-statistics.Rmd b/vignettes/testing-format-statistics.Rmd new file mode 100644 index 0000000..237f04a --- /dev/null +++ b/vignettes/testing-format-statistics.Rmd @@ -0,0 +1,38 @@ +--- +title: "Untitled" +author: "Jeetender Singh Chauhan" +date: "`r Sys.Date()`" +output: html_document +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` + + + +```{r , echo=FALSE} +library(metalite) +library(boxly) + +# Step 1: Source your modified prepare_boxly.R file +# (Update the path to where your modified file is saved) +source("~/boxly_format_mean_value/R/prepare_boxly.R") + +# Step 2: Create metadata +meta <- meta_boxly( + boxly_adsl, + boxly_adlb, + population_term = "apat", + observation_term = "wk12" +) + +# Step 3: Prepare data with 2 decimal places for mean +outdata <- prepare_boxly(meta, mean_decimal = 5) + +# Step 4: Generate the interactive box plot +boxly(outdata) + +``` + +Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. From f768992a66949311b17fcb640d4a79d21ba0c6eb Mon Sep 17 00:00:00 2001 From: jeetendersinghc Date: Thu, 19 Mar 2026 00:58:59 +0000 Subject: [PATCH 2/5] Style code (GHA) --- vignettes/testing-format-statistics.Rmd | 1 - 1 file changed, 1 deletion(-) diff --git a/vignettes/testing-format-statistics.Rmd b/vignettes/testing-format-statistics.Rmd index 237f04a..5e7762f 100644 --- a/vignettes/testing-format-statistics.Rmd +++ b/vignettes/testing-format-statistics.Rmd @@ -32,7 +32,6 @@ outdata <- prepare_boxly(meta, mean_decimal = 5) # Step 4: Generate the interactive box plot boxly(outdata) - ``` Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. From a47b4dccf1e76b587afbb9f0e4f29deda0e7aa06 Mon Sep 17 00:00:00 2001 From: chauhaje Date: Wed, 18 Mar 2026 21:01:29 -0400 Subject: [PATCH 3/5] Updated function to format mean value --- R/prepare_boxly.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/prepare_boxly.R b/R/prepare_boxly.R index 1b7134d..b9858a8 100644 --- a/R/prepare_boxly.R +++ b/R/prepare_boxly.R @@ -51,7 +51,8 @@ prepare_boxly <- function(meta, observation = NULL, analysis = NULL, filter_var = "PARAM", - hover_var_outlier = c("USUBJID", metalite::collect_adam_mapping(meta, analysis)$y)) { + hover_var_outlier = c("USUBJID", metalite::collect_adam_mapping(meta, analysis)$y), + mean_decimal = NULL) { if (is.null(population)) { if (length(meta$population) == 1) { population <- meta$population[[1]]$name @@ -179,7 +180,11 @@ prepare_boxly <- function(meta, ans$min <- vals[1] ans$q1 <- vals[2] ans$median <- vals[3] - ans$mean <- mean_val + if (!is.null(mean_decimal)) { + ans$mean <- round(mean_val, mean_decimal) + } else { + ans$mean <- mean_val + } ans$q3 <- vals[4] ans$max <- vals[5] From d68fad618e3fef0ebdd99f22d33015d4ef48a744 Mon Sep 17 00:00:00 2001 From: chauhaje Date: Wed, 22 Apr 2026 11:22:01 -0400 Subject: [PATCH 4/5] Added Example 4: Format means values in summary statistics with mean_decimal parameter --- vignettes/boxly.Rmd | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/vignettes/boxly.Rmd b/vignettes/boxly.Rmd index 50c6d9b..2ed562a 100644 --- a/vignettes/boxly.Rmd +++ b/vignettes/boxly.Rmd @@ -101,3 +101,59 @@ meta_boxly( prepare_boxly() |> boxly() ``` + + +## Example 4: Format Mean Values in Summary Statistics + +### Overview + +When displaying summary statistics in the interactive box plot hover labels, you may want to control +the precision (number of decimal places) of the mean value. The `mean_decimal` parameter in +`prepare_boxly()` allows you to format the mean values to a specific number of decimal places. + +This is particularly useful when you need to: + +- Match a specific reporting format required by your analysis plan or regulatory submission +- Improve readability by reducing unnecessary decimal places +- Ensure consistency with other statistics displayed in your report +- Control the level of precision shown to stakeholders + +### Basic Usage + +Use the `mean_decimal` parameter to specify the number of decimal places for rounding the mean value: + +```{r} +meta <- meta_boxly( + boxly_adsl, + boxly_adlb, + population_term = "apat", + observation_term = "wk12", + observation_subset = AVISITN <= 12 & !is.na(CHG) +) + +# Format mean values to 2 decimal places +outdata <- prepare_boxly(meta, mean_decimal = 2) +boxly(outdata) +``` + +### Example with Different Decimal Places + +```{r} +# Format mean values to 1 decimal place +meta_boxly( + boxly_adsl, + boxly_adlb, + population_term = "apat", + observation_term = "wk12", + observation_subset = AVISITN <= 12 & !is.na(CHG) +) |> + prepare_boxly(mean_decimal = 1) |> + boxly() +``` + +### Notes + +- When `mean_decimal` is `NULL` (default), the mean values are displayed with full precision (not rounded) +- The mean values are rounded using base R's `round()` function +- Other summary statistics (Min, Q1, Median, Q3, Max) are not affected by this parameter +- The formatted mean values will appear in the hover label when you move your cursor over the box plot From 2f25c6264a4e4bc159e2ac6d08b5f7ab7391d5a2 Mon Sep 17 00:00:00 2001 From: jeetendersinghc Date: Wed, 22 Apr 2026 15:25:53 +0000 Subject: [PATCH 5/5] Style code (GHA) --- vignettes/boxly.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vignettes/boxly.Rmd b/vignettes/boxly.Rmd index 2ed562a..6856e68 100644 --- a/vignettes/boxly.Rmd +++ b/vignettes/boxly.Rmd @@ -146,8 +146,8 @@ meta_boxly( population_term = "apat", observation_term = "wk12", observation_subset = AVISITN <= 12 & !is.na(CHG) -) |> - prepare_boxly(mean_decimal = 1) |> +) |> + prepare_boxly(mean_decimal = 1) |> boxly() ```