Skip to content

Commit

Permalink
ggbarstats p instead of asterisk
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Dec 2, 2020
1 parent d29ae77 commit a3074ab
Show file tree
Hide file tree
Showing 52 changed files with 114 additions and 91 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ importFrom(ipmisc,"%<>%")
importFrom(ipmisc,"%>%")
importFrom(ipmisc,as_tibble)
importFrom(ipmisc,enframe)
importFrom(ipmisc,signif_column)
importFrom(ipmisc,specify_decimal_p)
importFrom(ipmisc,stats_type_switch)
importFrom(ipmisc,tibble)
Expand Down
12 changes: 8 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ BUG FIXES

- Setting `mean.path = FALSE` in `ggwithinstats` produced incorrect colors for
points (#470). This bug was introduced in `0.6.5` and is now fixed.

- If user had set `options(scipen = 999)` in their session, the *p*-value
formatting for `ggpiestats` and `ggcoefstats` looked super-ugly (#478).
This has been fixed.
formatting for `ggpiestats` and `ggcoefstats` looked super-ugly (#478). This
has been fixed.

MAJOR CHANGES

Expand All @@ -38,7 +38,7 @@ MAJOR CHANGES
- `ggpiestats` and `ggbarstats` don't support returning dataframes. See FAQ
vignette on how to get these dataframes:
<https://indrajeetpatil.github.io/ggstatsplot/articles/web_only/faq.html#faq-1>

- `ggpiestats` and `ggbarstats` were not supposed to support returning Bayes
Factor for paired contingency table analysis, which is not supported in
`BayesFactor` itself.
Expand All @@ -47,6 +47,10 @@ MAJOR CHANGES
degrees of freedom are not available for `t`-statistic, they are displayed
to be `Inf`, in keeping with `easystats` conventions.

- Instead of showing significance of *p*-values with APA's asterisks
conventions, `ggbarstats` now instead shows the actual *p*-values from
one-sample proportion tests.

NEW FEATURES

- More models supported in `ggcoefstats`: `Glm`.
Expand Down
19 changes: 5 additions & 14 deletions R/ggbarstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,10 @@ ggbarstats <- function(data,
p <- p +
ggplot2::geom_text(
data = df_proptest,
mapping = ggplot2::aes(
x = {{ y }},
y = 1.05,
label = significance,
fill = NULL
),
size = 5,
na.rm = TRUE
mapping = ggplot2::aes(x = {{ y }}, y = 1.05, label = .p.label, fill = NULL),
size = 2.8,
na.rm = TRUE,
parse = TRUE
)
}

Expand All @@ -219,12 +215,7 @@ ggbarstats <- function(data,
p <- p +
ggplot2::geom_text(
data = df_proptest,
mapping = ggplot2::aes(
x = {{ y }},
y = -0.05,
label = N,
fill = NULL
),
mapping = ggplot2::aes(x = {{ y }}, y = -0.05, label = N, fill = NULL),
size = 4,
na.rm = TRUE
)
Expand Down
5 changes: 3 additions & 2 deletions R/ggpiestats.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#' (a goodness of fit test) will be run for the `x` variable. Otherwise an
#' appropriate association test will be run. This argument can not be `NULL`
#' for `ggbarstats` function.
#' @param proportion.test Decides whether proportion test for `x` variable is
#' to be carried out for each level of `y` (Default: `TRUE`).
#' @param proportion.test Decides whether proportion test for `x` variable is to
#' be carried out for each level of `y` (Default: `TRUE`). In `ggbarstats`,
#' only *p*-values from this test will be displayed.
#' @param perc.k Numeric that decides number of decimal places for percentage
#' labels (Default: `0`).
#' @param label Character decides what information needs to be displayed
Expand Down
3 changes: 2 additions & 1 deletion R/global_vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ utils::globalVariables(
"term",
"df",
".label",
".counts"
".counts",
".p.label"
),
package = "ggstatsplot",
add = FALSE
Expand Down
2 changes: 1 addition & 1 deletion R/helpers_ggbetweenstats_graphics.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @importFrom dplyr select group_by matches mutate rowwise group_modify arrange ungroup
#' @importFrom rlang !! enquo ensym :=
#' @importFrom tidyr drop_na
#' @importFrom ipmisc specify_decimal_p signif_column
#' @importFrom ipmisc specify_decimal_p
#'
#' @examples
#' # this internal function may not have much utility outside of the package
Expand Down
14 changes: 6 additions & 8 deletions R/helpers_ggcatstats_graphics.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ df_descriptive <- function(data,

# creating a dataframe with counts
cat_counter <- function(data, x, y = NULL, ...) {
data %>%
dplyr::group_by(.data = ., {{ y }}, {{ x }}, .drop = TRUE) %>%
dplyr::group_by(.data = data, {{ y }}, {{ x }}, .drop = TRUE) %>%
dplyr::tally(x = ., name = "counts") %>%
dplyr::mutate(.data = ., perc = (counts / sum(counts)) * 100) %>%
dplyr::ungroup(.) %>%
Expand All @@ -60,18 +59,16 @@ cat_counter <- function(data, x, y = NULL, ...) {
#'
#' @noRd

# combine info about sample size plus
df_proptest <- function(data, x, y, k = 3L, ...) {
# combine info about sample size plus proportion test
df_proptest <- function(data, x, y, k = 2L, ...) {
dplyr::full_join(
# descriptives
x = cat_counter(data = data, x = {{ y }}) %>%
dplyr::mutate(N = paste0("(n = ", .prettyNum(counts), ")")),
# proportion tests
y = dplyr::group_by(data, {{ y }}) %>%
dplyr::group_modify(.f = ~ chisq_test_safe(., {{ x }})) %>%
dplyr::ungroup(.) %>%
ipmisc::signif_column(data = ., p = p.value) %>%
dplyr::filter(.data = ., !is.na(significance)),
dplyr::ungroup(.),
by = rlang::as_name(rlang::ensym(y))
) %>%
dplyr::rowwise() %>%
Expand All @@ -87,7 +84,8 @@ df_proptest <- function(data, x, y, k = 3L, ...) {
"', ~italic(n)==",
counts,
")"
)
),
.p.label = paste0("list(~italic(p)=='", specify_decimal_p(p.value, k, TRUE), "')")
) %>%
dplyr::ungroup()
}
Expand Down
2 changes: 2 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ ggstatsplot::ggbarstats(
)
```

(The *p*-values from one-sample proportion test are displayed on top of each bar.)

And, needless to say, there is also a `grouped_` variant of this function-

```{r ggbarstats2, fig.height = 12, fig.width = 10}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,9 @@ ggstatsplot::ggbarstats(

<img src="man/figures/README-ggbarstats1-1.png" width="100%" />

(The *p*-values from one-sample proportion test are displayed on top of
each column.)

And, needless to say, there is also a `grouped_` variant of this
function-

Expand Down
17 changes: 11 additions & 6 deletions docs/articles/web_only/faq.html

Large diffs are not rendered by default.

Binary file modified docs/articles/web_only/faq_files/figure-html/ggbar_colors-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/web_only/gallery_files/figure-html/gallery2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/articles/web_only/ggbetweenstats.html

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

26 changes: 13 additions & 13 deletions docs/articles/web_only/ggcorrmat.html

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

2 changes: 1 addition & 1 deletion docs/articles/web_only/ggdotplotstats.html

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

2 changes: 1 addition & 1 deletion docs/articles/web_only/gghistostats.html

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions docs/articles/web_only/ggpiestats.html

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

2 changes: 1 addition & 1 deletion docs/articles/web_only/ggscatterstats.html

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

2 changes: 1 addition & 1 deletion docs/articles/web_only/ggwithinstats.html

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

4 changes: 2 additions & 2 deletions docs/articles/web_only/other_resources.html

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
1 change: 1 addition & 0 deletions docs/index.html

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

1 change: 1 addition & 0 deletions docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ articles:
web_only/purrr_examples: purrr_examples.html
web_only/session_info: session_info.html
web_only/theme_ggstatsplot: theme_ggstatsplot.html
last_built: 2020-12-01T23:14Z
last_built: 2020-12-02T18:57Z
urls:
reference: https://indrajeetpatil.github.io/ggstatsplot//reference
article: https://indrajeetpatil.github.io/ggstatsplot//articles
Expand Down
Binary file modified docs/reference/Rplot002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-ggbarstats1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-ggbarstats2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-ggscatterstats2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/ggbarstats-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

4 comments on commit a3074ab

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data-raw/Titanic_full.R:16:10: warning: 1:nrow(...) is likely to be wrong in the empty edge case, use seq_len.

df[rep(1:nrow(df), rep), ]
         ^

R/ggbetweenstats.R:155:1: style: functions should have cyclomatic complexity of less than 15, this has 24.

ggbetweenstats <- function(data,
^

R/ggcoefstats.R:200:1: style: functions should have cyclomatic complexity of less than 15, this has 40.

ggcoefstats <- function(x,
^

R/ggpiestats.R:67:1: style: functions should have cyclomatic complexity of less than 15, this has 23.

ggpiestats <- function(data,
^

R/ggscatterstats.R:90:1: style: functions should have cyclomatic complexity of less than 15, this has 22.

ggscatterstats <- function(data,
^

R/ggwithinstats.R:71:1: style: functions should have cyclomatic complexity of less than 15, this has 26.

ggwithinstats <- function(data,
^

R/ggwithinstats.R:165:1: style: Lines should not be more than 120 characters.

​    message('To get Bayes Factor, install GitHub version of `BayesFactor`:\n remotes::install_github("richarddmorey/BayesFactor/pkg/BayesFactor")')
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

R/helpers_gghistostats_graphics.R:180:3: warning: local variable ‘label.value’ assigned but may not be used

label.value <- x_pos
  ^~~~~~~~~~~

tests/testthat/test-ggbetweenstats.R:154:13: style: Commented code should be removed.

#       bold("only significant")
            ^~~~~~~~~~~~~~~~~~~~~~~~

tests/testthat/test-ggwithinstats.R:378:15: style: Commented code should be removed.

#       bold("only significant")
              ^~~~~~~~~~~~~~~~~~~~~~~~

vignettes/web_only/ggcoefstats.Rmd:180:3: style: Commented code should be removed.

# data("raceDolls")
  ^~~~~~~~~~~~~~~~~

vignettes/web_only/ggcoefstats.Rmd:185:7: style: Commented code should be removed.

#     fixedMargin = "cols"
      ^~~~~~~~~~~~~~~~~~~~

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data-raw/Titanic_full.R:16:10: warning: 1:nrow(...) is likely to be wrong in the empty edge case, use seq_len.

df[rep(1:nrow(df), rep), ]
         ^

R/ggbetweenstats.R:155:1: style: functions should have cyclomatic complexity of less than 15, this has 24.

ggbetweenstats <- function(data,
^

R/ggcoefstats.R:200:1: style: functions should have cyclomatic complexity of less than 15, this has 40.

ggcoefstats <- function(x,
^

R/ggpiestats.R:67:1: style: functions should have cyclomatic complexity of less than 15, this has 23.

ggpiestats <- function(data,
^

R/ggscatterstats.R:90:1: style: functions should have cyclomatic complexity of less than 15, this has 22.

ggscatterstats <- function(data,
^

R/ggwithinstats.R:71:1: style: functions should have cyclomatic complexity of less than 15, this has 26.

ggwithinstats <- function(data,
^

R/ggwithinstats.R:165:1: style: Lines should not be more than 120 characters.

​    message('To get Bayes Factor, install GitHub version of `BayesFactor`:\n remotes::install_github("richarddmorey/BayesFactor/pkg/BayesFactor")')
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

R/helpers_gghistostats_graphics.R:180:3: warning: local variable ‘label.value’ assigned but may not be used

label.value <- x_pos
  ^~~~~~~~~~~

tests/testthat/test-ggbetweenstats.R:154:13: style: Commented code should be removed.

#       bold("only significant")
            ^~~~~~~~~~~~~~~~~~~~~~~~

tests/testthat/test-ggwithinstats.R:378:15: style: Commented code should be removed.

#       bold("only significant")
              ^~~~~~~~~~~~~~~~~~~~~~~~

vignettes/web_only/ggcoefstats.Rmd:180:3: style: Commented code should be removed.

# data("raceDolls")
  ^~~~~~~~~~~~~~~~~

vignettes/web_only/ggcoefstats.Rmd:185:7: style: Commented code should be removed.

#     fixedMargin = "cols"
      ^~~~~~~~~~~~~~~~~~~~

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data-raw/Titanic_full.R:16:10: warning: 1:nrow(...) is likely to be wrong in the empty edge case, use seq_len.

df[rep(1:nrow(df), rep), ]
         ^

R/ggbetweenstats.R:155:1: style: functions should have cyclomatic complexity of less than 15, this has 24.

ggbetweenstats <- function(data,
^

R/ggcoefstats.R:200:1: style: functions should have cyclomatic complexity of less than 15, this has 40.

ggcoefstats <- function(x,
^

R/ggpiestats.R:67:1: style: functions should have cyclomatic complexity of less than 15, this has 23.

ggpiestats <- function(data,
^

R/ggscatterstats.R:90:1: style: functions should have cyclomatic complexity of less than 15, this has 22.

ggscatterstats <- function(data,
^

R/ggwithinstats.R:71:1: style: functions should have cyclomatic complexity of less than 15, this has 26.

ggwithinstats <- function(data,
^

R/ggwithinstats.R:165:1: style: Lines should not be more than 120 characters.

​    message('To get Bayes Factor, install GitHub version of `BayesFactor`:\n remotes::install_github("richarddmorey/BayesFactor/pkg/BayesFactor")')
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

R/helpers_gghistostats_graphics.R:180:3: warning: local variable ‘label.value’ assigned but may not be used

label.value <- x_pos
  ^~~~~~~~~~~

tests/testthat/test-ggbetweenstats.R:154:13: style: Commented code should be removed.

#       bold("only significant")
            ^~~~~~~~~~~~~~~~~~~~~~~~

tests/testthat/test-ggwithinstats.R:378:15: style: Commented code should be removed.

#       bold("only significant")
              ^~~~~~~~~~~~~~~~~~~~~~~~

vignettes/web_only/ggcoefstats.Rmd:180:3: style: Commented code should be removed.

# data("raceDolls")
  ^~~~~~~~~~~~~~~~~

vignettes/web_only/ggcoefstats.Rmd:185:7: style: Commented code should be removed.

#     fixedMargin = "cols"
      ^~~~~~~~~~~~~~~~~~~~

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data-raw/Titanic_full.R:16:10: warning: 1:nrow(...) is likely to be wrong in the empty edge case, use seq_len.

df[rep(1:nrow(df), rep), ]
         ^

R/ggbetweenstats.R:155:1: style: functions should have cyclomatic complexity of less than 15, this has 24.

ggbetweenstats <- function(data,
^

R/ggcoefstats.R:200:1: style: functions should have cyclomatic complexity of less than 15, this has 40.

ggcoefstats <- function(x,
^

R/ggpiestats.R:67:1: style: functions should have cyclomatic complexity of less than 15, this has 23.

ggpiestats <- function(data,
^

R/ggscatterstats.R:90:1: style: functions should have cyclomatic complexity of less than 15, this has 22.

ggscatterstats <- function(data,
^

R/ggwithinstats.R:71:1: style: functions should have cyclomatic complexity of less than 15, this has 26.

ggwithinstats <- function(data,
^

R/ggwithinstats.R:165:1: style: Lines should not be more than 120 characters.

​    message('To get Bayes Factor, install GitHub version of `BayesFactor`:\n remotes::install_github("richarddmorey/BayesFactor/pkg/BayesFactor")')
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

R/helpers_gghistostats_graphics.R:180:3: warning: local variable ‘label.value’ assigned but may not be used

label.value <- x_pos
  ^~~~~~~~~~~

tests/testthat/test-ggbetweenstats.R:154:13: style: Commented code should be removed.

#       bold("only significant")
            ^~~~~~~~~~~~~~~~~~~~~~~~

tests/testthat/test-ggwithinstats.R:378:15: style: Commented code should be removed.

#       bold("only significant")
              ^~~~~~~~~~~~~~~~~~~~~~~~

vignettes/web_only/ggcoefstats.Rmd:180:3: style: Commented code should be removed.

# data("raceDolls")
  ^~~~~~~~~~~~~~~~~

vignettes/web_only/ggcoefstats.Rmd:185:7: style: Commented code should be removed.

#     fixedMargin = "cols"
      ^~~~~~~~~~~~~~~~~~~~

Please sign in to comment.