sm_bar {smplot2} | R 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:
Default: |
err.params |
A list of parameters for customizing the error bars. Common parameters include:
Default: |
point.params |
A list of parameters for customizing individual points. Common parameters include:
Default: |
errorbar_type |
A string specifying the type of error bars to display:
|
point_jitter_width |
A numeric value specifying the degree of horizontal jitter applied to individual points.
|
points |
Logical. Determines whether individual points are displayed:
|
borders |
Logical. Determines whether grid borders are displayed:
|
legends |
Logical. Determines whether legends are displayed:
|
seed |
A numeric value to set a random seed for reproducible jittered points.
Default: |
forget |
Logical. Determines whether to apply the default aesthetic parameters:
|
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'))