From 3362ff0a950928b26af1d063fcb8aa8fdf26f450 Mon Sep 17 00:00:00 2001 From: Samer Mouksassi Date: Wed, 21 Aug 2024 10:54:07 +0300 Subject: [PATCH] added arguments to N mean and N median position by updatign give.n utility function in global based on recent projects continue to work on the ER functions --- NEWS.md | 2 +- inst/shinyapp/global.R | 22 ++++++++++++++++------ inst/shinyapp/ui.R | 10 ++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4a59a60..65212c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ # ggquickeda 0.3.1.9000 - +* added to possible positions on where to put the N of observations in Mean and Median tabs: (fixed, mean, median) * added arguments `show.exptile_values`, `show.exptile_values_pos` and `show.exptile_values_order` to `ggkmrisktable()` requested by Mathilde * fixes for `gglogisticexpdist()` and `ggcontinuousexpdist()` when `exposure_distribution`and `exposure_metric_split` where set to "none" diff --git a/inst/shinyapp/global.R b/inst/shinyapp/global.R index 851d6bb..62b8b6c 100644 --- a/inst/shinyapp/global.R +++ b/inst/shinyapp/global.R @@ -78,17 +78,27 @@ mean.n <- function(x, nroundlabel = 2, labeltrans =c("none","exp") ){ return(c(y = meanxvalue, label = meanxlabel )) } -give.n <- function(x, nposition = c("min","max","below","up"), + +give.n <- function(x, + nposition = c("min","max","below","up","fixed","mean","median"), mult = 1, add = 0 ){ - if ( nposition == "below"){ + if (nposition == "min"){ + yposition <- min(x)*mult + add + } else if (nposition == "max") { + yposition <- max(x)*mult + add + } else if (nposition == "below") { yposition <- -Inf } else if (nposition == "up") { yposition <- Inf - } else if (nposition == "min"){ - yposition <- min(x)*mult + add - } else - yposition <- max(x)*mult + add + } else if (nposition == "fixed") { + yposition <- add + } else if (nposition == "mean") { + yposition <- mean(x, na.rm = TRUE)*mult + add + } else if (nposition == "median") { + yposition <- median(x, na.rm = TRUE)*mult + add + } + else yposition <- 0 return(c(y = yposition, label = length(x))) } diff --git a/inst/shinyapp/ui.R b/inst/shinyapp/ui.R index 26fbc2a..15d4f9f 100644 --- a/inst/shinyapp/ui.R +++ b/inst/shinyapp/ui.R @@ -1958,7 +1958,10 @@ function(request) { radioButtons("mean_N_position", "N Positioning:", c("min" = "min","max" = "max", "lower/left edge" = "below", - "upper/right edge" = "up" + "upper/right edge" = "up", + "at add adj value" = "fixed", + "at mean value" ="mean", + "at median value" ="median" ), inline = TRUE), numericInput("mean_N_add",label = "N Additive adjustment", value = 0, min = NA, max = NA, step = 0.1), @@ -2135,7 +2138,10 @@ function(request) { radioButtons("median_N_position", "N Positioning:", c("min" = "min","max" = "max", "lower/left edge" = "below", - "upper/right edge" = "up" + "upper/right edge" = "up", + "at add adj value" = "fixed", + "at mean value" ="mean", + "at median value" ="median" ), inline = TRUE), numericInput("median_N_add",label = "N Additive adjustment", value = 0, min = NA, max = NA, step = 0.1),