letter_groups: Statistical plot annotation

Description Usage Arguments Examples

View source: R/letter_groups.R

Description

This is a simple wrapper function that outputs a data frame that can be used to annotate your plot with letter codes according to significant differences between groups. The function currently supports the parametric Tukey HSD test from 'stats' and the non-parametric Kruskal-Wallis test with Dunn's test for multiple comparisons from 'dunn.test'. In addition to the data and formula, the function takes as input a positional variable for placement on the plot, the threshold for statistical significance alpha, the method for p-value adjustment, and grouping variables for faceted plots.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
letter_groups(
  df,
  y,
  x,
  stat_method,
  ...,
  print_position = 0,
  print_adjust = 1,
  stat_alpha = 0.05,
  p_adj_method = "holm",
  table = FALSE
)

Arguments

df

A data frame.

y

The name of the y (dependent) variable.

x

The name of the x (independent) variable.

stat_method

The statistical test applied. Either "tukey" or "kruskal".

...

Any number of grouping variables for faceted plots.

print_position

The y position at which the letter annotation will be placed in the plot. One of "above", "mean", "below", or a numeric value.

print_adjust

Adjustment of the letter position multiples of the overall standard deviations. Defaults to 1.

stat_alpha

The significance threshold alpha. Defaults to 0.05.

p_adj_method

Method for p value adjustment, see ?dunn.test::dunn.test for details. One of "none", "bonferroni", "sidak", "holm", "hs", "hochberg", "bh", "by". Defaults to "holm".

table

A logical value indicating whether to return a data frame with the letter codes according to significance (table = FALSE, default), or a table containing the calculated statistics (P-values, df, etc.).

Examples

1
2
test_data <- tibble(value = rnorm(1000), sample = sample(LETTERS[1:5], 1000, replace = TRUE), group = sample(LETTERS[24:26], 1000, replace = TRUE))
annotation_df <- letter_groups(test_data, value, sample, "tukey", group, stat_alpha = 0.001, print_position = "above", print_adjust = 0.5, p_adj_method = "holm", table = FALSE)

leonardblaschek/tukeygrps documentation built on Sept. 26, 2021, 9:15 a.m.