Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed May 18, 2024
1 parent 1dc322d commit 18c8921
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
12 changes: 5 additions & 7 deletions R/ggbarstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ggbarstats <- function(
# untable the data frame based on the count for each observation
if (".counts" %in% names(data)) data %<>% tidyr::uncount(weights = .counts)

# x and y need to be a factor; also drop the unused levels of the factors
# x and y need to be a factor
data %<>% mutate(across(.cols = everything(), .fns = ~ as.factor(.x)))

# TO DO: until one-way table is supported by `BayesFactor`
Expand Down Expand Up @@ -126,7 +126,6 @@ ggbarstats <- function(
# if no. of factor levels is greater than the default palette color count
.is_palette_sufficient(package, palette, nlevels(pull(data, {{ x }})))

# plot
plotBar <- ggplot(descriptive_df, aes({{ y }}, perc, fill = {{ x }})) +
geom_bar(stat = "identity", position = "fill", color = "black") +
scale_y_continuous(
Expand All @@ -145,9 +144,8 @@ ggbarstats <- function(
guides(fill = guide_legend(title = legend.title %||% as_name(x))) +
paletteer::scale_fill_paletteer_d(paste0(package, "::", palette), name = "")

# sample size + proportion test ------------------------------------------
# proportion test ------------------------------------------

# adding significance labels to bars for proportion tests
if (isTRUE(proportion.test)) {
plotBar <- plotBar +
geom_text(
Expand All @@ -158,7 +156,8 @@ ggbarstats <- function(
)
}

# adding sample size info
# sample size -------------------------------------------------

plotBar <- plotBar +
exec(
geom_text,
Expand Down Expand Up @@ -207,13 +206,12 @@ ggbarstats <- function(
#' set.seed(123)
#' library(dplyr, warn.conflicts = FALSE)
#'
#' # let's create a smaller data frame
#' # let's create a smaller data frame first
#' diamonds_short <- ggplot2::diamonds %>%
#' filter(cut %in% c("Very Good", "Ideal")) %>%
#' filter(clarity %in% c("SI1", "SI2", "VS1", "VS2")) %>%
#' sample_frac(size = 0.05)
#'
#' # plot
#' grouped_ggbarstats(
#' data = diamonds_short,
#' x = color,
Expand Down
2 changes: 1 addition & 1 deletion R/ggpiestats.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ggpiestats <- function(
# untable the data frame based on the count for each observation
if (".counts" %in% names(data)) data %<>% tidyr::uncount(weights = .counts)

# x and y need to be a factor; also drop the unused levels of the factors
# x and y need to be a factor
data %<>% mutate(across(.cols = everything(), .fns = ~ as.factor(.x)))
x_levels <- nlevels(pull(data, {{ x }}))
y_levels <- ifelse(test == "one.way", 0L, nlevels(pull(data, {{ y }})))
Expand Down
3 changes: 1 addition & 2 deletions man/grouped_ggbarstats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 18c8921

Please sign in to comment.