raincloud | R Documentation |
The raincloud()
function allows to generate distribution plots
for continuous data in an easy and uncomplicated way. The function is based
on the ggplot2
package, which must already be preinstalled Raincloud
plots consist of three main elements:
Distribution plots, specifically violin plots with the mean values and standard deviations of respective groups,
Jittered point plots depicting the underlying distribution of the data in the rawest form,
Boxplots, summarizing the most important statistics of the underlying distribution.
raincloud(
data = NULL,
y = NULL,
group = NULL,
facet = NULL,
ncol = 1,
significance = NULL,
sig_label_size = 2L,
sig_label_color = FALSE,
smd_type = "mean",
limits = NULL,
jitter = 0.1,
alpha = 0.4,
plot_name = NULL,
overwrite = FALSE,
...
)
data |
A non-empty |
y |
A single string or unquoted symbol representing the name of a
numeric column in the |
group |
A single string or unquoted symbol representing the name of a
factor or character column in |
facet |
A single string or unquoted symbol representing the name of a
variable in |
ncol |
A single integer. The value should be less than or equal to the
number of unique categories in the |
significance |
A single string specifying the method for calculating
p-values in multiple comparisons between groups defined by the |
sig_label_size |
An integer specifying the size of the significance and SMD (standardized mean difference) labels displayed on the bars on the right side of the plot. |
sig_label_color |
Logical flag. If |
smd_type |
A single string indicating the type of effect size to calculate and display on the left side of the jittered point plots:
|
limits |
A numeric atomic vector of length two, specifying the |
jitter |
A single numeric value between 0 and 1 that controls the amount
of jitter applied to points in the |
alpha |
A single numeric value between 0 and 1 that controls the
transparency of the density plots, boxplots, and jittered point plots.
Lower values result in higher transparency. It is recommended to keep this
value relatively high to maintain the interpretability of the plots when
using the |
plot_name |
A string specifying a valid file name or path for the plot.
If set to |
overwrite |
A logical flag (default |
... |
Additional arguments passed to the function for calculating
p-values when the |
Available methods for the argument significance
are:
"t_test"
- Performs a pairwise comparison using the two-sample t-test,
with the default Holm adjustment for multiple comparisons. This test assumes
normally distributed data and equal variances. The adjustment can be
modified via the p.adjust.method
argument. The test is implemented via
rstatix::pairwise_t_test()
"dunn_test"
- Executes Dunn's test for pairwise comparisons following a
Kruskal-Wallis test. It is a non-parametric alternative to the t-test when
assumptions of normality or homogeneity of variances are violated.
Implemented via rstatix::dunn_test()
.
"tukeyHSD_test"
- Uses Tukey's Honest Significant Difference (HSD) test
for pairwise comparisons between group means. Suitable for comparing all
pairs when the overall ANOVA is significant. The method assumes equal
variance between groups and is implemented via rstatix::tukey_hsd()
.
"games_howell_test"
- A post-hoc test used after ANOVA, which does not
assume equal variances or equal sample sizes. It’s particularly robust for
data that violate homogeneity of variance assumptions. Implemented via
rstatix::games_howell_test()
.
"wilcoxon_test"
- Performs the Wilcoxon rank-sum test (also known as the
Mann-Whitney U test) for non-parametric pairwise comparisons. Useful when
data are not normally distributed. Implemented via
rstatix::pairwise_wilcox_test()
.
A ggplot
object representing the distribution of the y
variable
across the levels of the group
and facet
variables in data
.
mosaic()
which summarizes the distribution of discrete data
## Example: Creating a raincloud plot for the ToothGrowth dataset.
## This plot visualizes the distribution of the `len` variable by
## `dose` (using different colors) and facets by `supp`. Group
## differences by `dose` are calculated using a `t_test`, and standardized
## mean differences (SMDs) are displayed through jittered points.
library(ggplot2)
library(ggpubr)
p <- raincloud(ToothGrowth, len, dose, supp,
significance = "t_test",
jitter = 0.15, alpha = 0.4
)
## As `p` is a valid `ggplot` object, we can manipulate its
## characteristics usingthe `ggplot2` or `ggpubr` packages
## to create publication grade plot:
p <- p +
theme_classic2() +
theme(
axis.line.y = element_blank(),
axis.ticks.y = element_blank()
) +
guides(fill = guide_legend("Dose [mg]")) +
ylab("Length [cm]")
p
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.