Descriptive plot of categorical variable (x-axis) vs. a continuous variable (y-axis)

descriptivesPlot(
  x,
  y,
  ciLower = NULL,
  ciUpper = NULL,
  xName = NULL,
  yName = NULL,
  group = NULL,
  groupName = NULL,
  horizontalLine = NULL,
  horizontalLineLineType = "dashed",
  position = ggplot2::position_dodge(0.2),
  lineSize = 0.7,
  pointSize = 4,
  errorbarWidth = 0.2,
  noXLevelNames = length(x) == 1L,
  breaksAtExtremaOnly = TRUE,
  connectedPoints = TRUE,
  legendPosition = if (is.null(group)) "none" else "right"
)

Arguments

x

character vector indicating the groups shown on the x-axis.

y

numeric vector indicating the y-values.

ciLower

numeric vector with the lower bound of the confidence interval.

ciUpper

numeric vector with the upper bound of the confidence interval.

xName

character, name to use as the x-axis title.

yName

character, name to use as the y-axis title.

group

character vector indicating group membership, which is used for shape and fill color

groupName

character, name to show as the legend title.

horizontalLine

numeric, draw a horizontal asymptote at this y-value.

horizontalLineLineType

line type of the horizontal asymptote.

position

a value for the position argument of e.g., geom_line.

lineSize

a value for the size argument of geom_line.

pointSize

a value for the size argument of geom_point.

errorbarWidth

a value for the width argument of geom_errorbar.

noXLevelNames

Logical, should the level names on the x-axis be hidden?

breaksAtExtremaOnly

Logical, Should only the outermost y-axis breaks be shown?

connectedPoints

Logical, Should the dots be connected with lines?

legendPosition

Indicate the legend position (passed to theme).

Value

a ggplot2 object.

Examples

x <- "A"
y <- -0.188
ciLower <- y - .1
ciUpper <- y + .1
descriptivesPlot(x, y, ciLower, ciUpper, horizontalLine = -.1)



x <- c("Fast", "Slow")
y <- c(15, 22)
ciLower <- y - 3
ciUpper <- y + 3
xName <- "Condition"
yName <- "Response time"

descriptivesPlot(x, y, ciLower, ciUpper, xName, yName, horizontalLine = 18.5)


x <- c("0", "1", "0", "1")
y <- c(15, 22, 16, 21)
ciLower <- y - 3
ciUpper <- y + 3
xName <- "contBinom"
group <- c("m", "m", "f", "f")
groupName <- "facGender"
descriptivesPlot(x, y, ciLower, ciUpper, xName, group = group, groupName = groupName,
                 horizontalLine = 19)


set.seed(42)
kx <- 5
kg <- 20
n  <- kx * kg
x <- as.character(rep(1:kx, kg))
y <- rnorm(n, 10 + 10 * as.numeric(x), 2)
ciLower <- y - rnorm(n, 3 * as.numeric(x), 2)
ciUpper <- y + rnorm(n, 3 * as.numeric(x), 2)
group <- rep(seq_len(kg), each = kx)
xName <- "Groups"
yName <- "Performance"
groupName <- "Legend title"
descriptivesPlot(x, y, ciLower, ciUpper, xName, yName, group = group, groupName = groupName,
                 breaksAtExtremaOnly = FALSE, connectedPoints = FALSE)