sm_raincloud | R Documentation |
Creates a raincloud plot, a combination of jittered points, boxplots, and violin plots. Inspired by the 'raincloudplots' R package by Jordy van Langen, this function offers enhanced customization and automatic sorting of data based on the x-axis factor levels.
This function allows detailed control over the aesthetics of individual components (boxplot, violin, and points) and provides options to adjust layout and orientation.
sm_raincloud(
...,
boxplot.params = list(),
violin.params = list(alpha = 0.3, color = "transparent"),
point.params = list(alpha = 1, size = 3, shape = 21, color = "transparent"),
which_side = "r",
sep_level = 2,
point_jitter_width = 0.12,
vertical = TRUE,
points = TRUE,
borders = TRUE,
legends = FALSE,
seed = NULL,
forget = FALSE
)
... |
Additional aesthetic parameters applied across all elements (points, boxplot, and violin plot). Optional. |
boxplot.params |
A list of parameters for customizing the boxplot. Common options include:
Default: |
violin.params |
A list of parameters for customizing the violin plot. Common options include:
Default: |
point.params |
A list of parameters for customizing individual points. Common options include:
Default: |
which_side |
Specifies the side of the violin and boxplots. Options:
The |
sep_level |
A numeric value (0-4) controlling the separation level among the boxplot, violin plot, and points:
Default: |
point_jitter_width |
A numeric value determining the horizontal jitter for individual points:
|
vertical |
Logical. Specifies the orientation of the plot:
|
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 list of ggplot2 layers for creating a raincloud plot.
library(ggplot2)
library(smplot2)
set.seed(2) # generate random data
day1 = rnorm(20,0,1)
day2 = rnorm(20,5,1)
day3 = rnorm(20,6,1.5)
day4 = rnorm(20,7,2)
Subject <- rep(paste0('S',seq(1:20)), 4)
Data <- data.frame(Value = matrix(c(day1,day2,day3,day4),ncol=1))
Day <- rep(c('Day 1', 'Day 2', 'Day 3', 'Day 4'), each = length(day1))
df2 <- cbind(Subject, Data, Day)
ggplot(data=df2, aes(x = Day, y = Value, color = Day, fill = Day)) +
sm_raincloud() +
xlab('Day') +
scale_fill_manual(values = sm_palette(4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.