Adds statistical significance brackets and labels between groups.
This is a syntax-sugar composite mark that combines
mark_rule and mark_text internally.
Usage
mark_significance(
plot,
comparisons,
y_position = NULL,
y_offset = NULL,
line_colour = "grey30",
line_width = 0.3,
text_size = 3.5,
tip_length = 0.02,
...
)Arguments
- plot
A plotit object
- comparisons
A data frame with columns:
group1,group2,label, and optionallyy_position. Character columns are matched against the x-axis variable.- y_position
Numeric vector of y-positions for the brackets. If omitted, auto-computed from data range.
- y_offset
Text offset above the bracket line (default 0.5). In data units.
- line_colour
Colour for the bracket lines (default
"grey30").- line_width
Width of bracket lines (default 0.3).
- text_size
Size of significance label text (default 3.5).
- tip_length
Length of bracket end-tick lines (default 0.02 as fraction of x-axis range).
- ...
Additional arguments passed to
mark_text()
Examples
df <- data.frame(group = c("A", "B", "C"), value = c(5, 8, 4))
comp <- data.frame(
group1 = c("A", "A"), group2 = c("B", "C"),
label = c("**", "ns"))
plotit(df, encode(x = group, y = value)) |>
mark_bar() |>
mark_significance(comp, y_position = c(9, 6))
#> Warning: All aesthetics have length 1, but the data has 3 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.
#> Warning: All aesthetics have length 1, but the data has 3 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.
#> Warning: All aesthetics have length 1, but the data has 3 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.
#> Warning: All aesthetics have length 1, but the data has 3 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.
#> Warning: All aesthetics have length 1, but the data has 3 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.
#> Warning: All aesthetics have length 1, but the data has 3 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.
#> Warning: All aesthetics have length 1, but the data has 3 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.
#> Warning: All aesthetics have length 1, but the data has 3 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing
#> a single row.