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),