sm_bar: Bar Plot with Jittered Individual Points

View source: R/sm_bar2.R

sm_barR Documentation

Bar Plot with Jittered Individual Points

Description

Generates a bar plot with optional jittered individual points and error bars. The function supports flexible customization of the bars, points, and error bars, and allows for displaying standard deviation, standard error, or confidence intervals.

Usage

sm_bar(
  ...,
  bar.params = list(width = 0.7, alpha = 1, color = "transparent", fill = "gray80"),
  err.params = list(linewidth = 1, color = "black"),
  point.params = list(size = 2.5, alpha = 0.65, shape = 16),
  errorbar_type = "se",
  point_jitter_width = 0.12,
  points = TRUE,
  borders = TRUE,
  legends = FALSE,
  seed = NULL,
  forget = FALSE
)

Arguments

...

Additional aesthetic parameters applied across points, bars, and error bars. Optional.

bar.params

A list of parameters for customizing the bar graph. Common parameters include:

  • fill: Fill color of the bars.

  • color: Outline color of the bars.

  • alpha: Transparency level of the bars.

  • width: Width of the bars.

Default: list(width = 0.7, alpha = 1, color = 'transparent', fill = 'gray80').

err.params

A list of parameters for customizing the error bars. Common parameters include:

  • color: Color of the error bars.

  • size: Size of the error bar endpoints.

  • linewidth: Width of the error bar lines.

Default: list(linewidth = 1, color = 'black').

point.params

A list of parameters for customizing individual points. Common parameters include:

  • size: Size of the points.

  • alpha: Transparency level of the points.

  • shape: Shape of the points.

  • color: Color of the points.

Default: list(size = 2.5, alpha = 0.65, shape = 16).

errorbar_type

A string specifying the type of error bars to display:

  • 'se': Standard error.

  • 'sd': Standard deviation (default).

  • 'ci': 95

point_jitter_width

A numeric value specifying the degree of horizontal jitter applied to individual points.

  • If set to 0, points are aligned along the y-axis without jitter.

  • Default: 0.12.

points

Logical. Determines whether individual points are displayed:

  • TRUE: Display points (default).

  • FALSE: Hide points.

borders

Logical. Determines whether grid borders are displayed:

  • TRUE: Display borders (default).

  • FALSE: Remove borders.

legends

Logical. Determines whether legends are displayed:

  • TRUE: Display legends.

  • FALSE: Hide legends (default).

seed

A numeric value to set a random seed for reproducible jittered points. Default: NULL (no seed).

forget

Logical. Determines whether to apply the default aesthetic parameters:

  • TRUE: Ignore default aesthetic parameters (bar.params, err.params, and point.params) and apply only user-supplied customizations.

  • FALSE: Merge user-supplied customizations with the defaults (default).

Value

A ggplot2 object representing a bar graph with optional jittered points and error bars.

Examples

library(smplot2)
library(ggplot2)
set.seed(1) # generate random data
day1 = rnorm(16,2,1)
day2 = rnorm(16,5,1)
Subject <- rep(paste0('S',seq(1:16)), 2)
Data <- data.frame(Value = matrix(c(day1,day2),ncol=1))
Day <- rep(c('Day 1', 'Day 2'), each = length(day1))
df <- cbind(Subject, Data, Day)

# with aesthetic defaults of smplot
ggplot(data = df, mapping = aes(x = Day, y = Value, color = Day)) +
sm_bar() +
scale_color_manual(values = sm_color('blue','orange'))


smin95/sesR documentation built on Feb. 3, 2025, 10:51 p.m.