plotsig: Display significance in ggplot2 plots

Description Usage Arguments Examples

Description

A convenience function for displaying significance in ggplot2 plots

Usage

1
2
3
4
plotsig(x_lo, x_hi, y_lo_left, y_lo_right, y_hi, label = "*",
  label_margin = 0.5, text_size = 8, line_size = 0.3, x_lo_lo = NULL,
  x_lo_hi = NULL, x_hi_lo = NULL, x_hi_hi = NULL, span_y = 1,
  color = "black", family = "")

Arguments

x_lo

numeric, x position of left line ending

x_hi

numeric, x position of right line ending

y_lo_left

numeric, corresponding lower y position for x_lo

y_lo_right

numeric, corresponding lower y position for x_hi

y_hi

numeric, corresponding upper y-position for x_lo and x_hi

label

character, text label to display, default is "*"

label_margin

numeric, margin between y_hi and the text label, default is .5

text_size

numeric, text size for label, default is 8

line_size

numeric, size of line elements, default is .3

x_lo_lo

numeric, if the left line ending (x_lo) should span over multiple values, then x_lo_lo defines the leftmost position.

x_lo_hi

numeric, corresponding rightmost value for x_lo_lo

x_hi_lo

numeric, if the right line ending (x_hi) should span over multiple values, then x_hi_lo defines the leftmost position.

x_hi_hi

numeric, corresponding rightmost value for x_hi_lo

span_y

numeric, y length of the bracket for x_lo_lo/x_lo_hi and/or x_hi_lo/x_hi_hi

color

character, color of label and line elements.

family

character, font family

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library(ggplot2)

data <- data.frame(group = c("a", "b"), mean = c(20, 30), se = c(2.5, 3.0))

ggplot(data, aes(x = group, y = mean)) +
  geom_bar(stat = "identity") +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = .5) +
  plotsig(1, 2, 25, 35, 40)

data <- data.frame(factor1 = rep(letters[1:2], each = 2),
                   factor2 = rep(letters[3:4], times = 2),
                   mean = c(10, 12, 20, 35),
                   se = c(2.4, 3, 2.9, 3.1))

ggplot(data, aes(x = factor1, y = mean, fill = factor2)) +
  geom_bar(stat = "identity", position = "dodge") +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = .5,
                position = position_dodge(.9)) +
  plotsig(1.775, 2.225, 25, 40, 45) +
  plotsig(1, 2, 20, 50, 55, x_lo_lo = .55, x_lo_hi = 1.45, x_hi_lo = 1.55,
         x_hi_hi = 2.45)

dgromer/psymisc documentation built on May 15, 2019, 7:22 a.m.