Skip to content

Commit

Permalink
update of add significance for %
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewphamilton committed Nov 11, 2024
1 parent 24eb5ba commit 00a600f
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 377 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ Description: ready4use provides a set of tools for managing data for
of the ready4use package has been made available as part of the
process of testing and documenting the package. If you have any
questions, please contact the authors ([email protected]).
License: GPL-3 + file LICENSE
License: GPL-3
URL: https://ready4-dev.github.io/ready4use/,
https://github.com/ready4-dev/ready4use, https://www.ready4-dev.com/
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Suggests:
knitr,
pkgload,
rmarkdown,
testthat
VignetteBuilder: knitr
Expand Down
18 changes: 13 additions & 5 deletions R/fn_add.R
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ add_latest_match <- function (data_tb, dynamic_lup, target_var_nm_1L_chr, date_v
#' @param var_1L_chr Variable (a character vector of length one)
#' @param add_1L_dbl Add (a double vector of length one), Default: numeric(0)
#' @param adjust_1L_dbl Adjust (a double vector of length one), Default: 0.4
#' @param as_percent_1L_lgl As percent (a logical vector of length one), Default: F
#' @param digits_1L_int Digits (an integer vector of length one), Default: 4
#' @param scientific_1L_lgl Scientific (a logical vector of length one), Default: F
#' @param show_p_1L_lgl Show p (a logical vector of length one), Default: T
Expand All @@ -363,22 +364,29 @@ add_latest_match <- function (data_tb, dynamic_lup, target_var_nm_1L_chr, date_v
#' @importFrom ggsignif geom_signif
#' @keywords internal
add_significance <- function (plot_plt, by_1L_chr, data_tb, var_1L_chr, add_1L_dbl = numeric(0),
adjust_1L_dbl = 0.4, digits_1L_int = 4, scientific_1L_lgl = F,
show_p_1L_lgl = T, show_test_1L_lgl = F, tip_1L_dbl = 0,
...)
adjust_1L_dbl = 0.4, as_percent_1L_lgl = F, digits_1L_int = 4,
scientific_1L_lgl = F, show_p_1L_lgl = T, show_test_1L_lgl = F,
tip_1L_dbl = 0, ...)
{
df <- make_significance_df(data_tb, by_1L_chr = by_1L_chr,
vars_chr = var_1L_chr)
x_axis_chr <- ggplot2::ggplot_build(plot_plt)$layout$panel_params[[1]]$x$get_labels()
if (!identical(add_1L_dbl, numeric(0))) {
y_axis_max_1L_dbl <- ggplot2::ggplot_build(plot_plt)$layout$panel_params[[1]]$y$get_labels() %>%
y_axis_dbl <- ggplot2::ggplot_build(plot_plt)$layout$panel_params[[1]]$y$get_labels() %>%
stringr::str_remove_all("%") %>% purrr::discard(is.na) %>%
as.numeric() %>% max()
as.numeric()
y_axis_max_1L_dbl <- y_axis_dbl %>% max()
y_position <- y_axis_max_1L_dbl + add_1L_dbl
if (as_percent_1L_lgl) {
y_position <- y_position/100
}
}
else {
y_position <- NULL
}
if (as_percent_1L_lgl) {
tip_1L_dbl <- tip_1L_dbl/100
}
label_1L_chr <- paste0(ifelse(show_p_1L_lgl, paste0("p=",
format(round(df$p.value, digits_1L_int), scientific = scientific_1L_lgl),
" ")), df$stars, ifelse(show_test_1L_lgl, paste0(" ",
Expand Down
Loading

0 comments on commit 00a600f

Please sign in to comment.