sm_violin | R Documentation |
Generates a violin plot with optional jittered individual points and error bars. This function allows for flexible customization of the violin, points, and error bars, and supports displaying standard deviation, standard error, or confidence intervals as error bars.
sm_violin(
...,
violin.params = list(fill = "gray90", color = "transparent"),
err.params = list(size = 1.2, linewidth = 1.2),
point.params = list(alpha = 0.25, size = 2),
errorbar_type = "sd",
point_jitter_width = 0.17,
points = TRUE,
borders = TRUE,
legends = FALSE,
seed = NULL,
forget = FALSE
)
... |
Additional aesthetic parameters applied across points, the violin plot, and error bars. Optional. |
violin.params |
A list of parameters for customizing the violin plot. 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:
|
A ggplot2 object containing a violin plot with optional jittered points and error bars.
library(ggplot2)
library(smplot2)
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_violin() +
scale_color_manual(values = sm_color('blue','orange'))
# without aesthetic defaults of smplot
ggplot(data = df, mapping = aes(x = Day, y = Value, color = Day)) +
sm_violin(violin.params = list()) +
scale_color_manual(values = sm_color('blue','orange'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.