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 statistical test applied is either the parametric Tukey HSD or the non-parametric Kruskal-Wallis. 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. The underlying statistical functions are called from the 'agricolae' package.

Usage

1
2
letter_groups(df, y, x, stat_method, ..., print_position = 0,
  print_adjust = 1, stat_alpha = 0.05, p_adj_method = "holm")

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 for the the Kruskal-Wallis test. Defaults to 0.05.

p_adj_method

Method for p value adjustment. One of "none","holm","hommel", "hochberg", "bonferroni", "BH", "BY" or "fdr". Defaults to "holm".

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 <- kruskal_groups(test_data, value, sample, "tukey", group, stat_alpha = 0.001, print_position = "above", print_adjust = 0.5, p_adj_method = "bonferroni")

leonardblaschek/tukeygrps documentation built on Nov. 5, 2019, 7:12 p.m.