plot_raincloud {sdamr} | R Documentation |
Create a raincloud plot
Description
plot_raincloud
creates a raincloud plot to display the distribution of data by a combination of a a boxplot, a kernel density plot, and a scatterplot. The boxplot includes the median (displayed as a horizontal line) and the mean (displayed as a point). It does not indicate potential outliers, as these can be seen in the scatter plot. The kernel density plot provides a nonparametric estimate of the distribution. The scatterplot depicts all values in y
with random jittering on the x-axis. The data can be grouped by supplying a grouping factor in the groups
argument, in which case multiple raincloud plots are shown side by side. As plot_raincloud
provides a ggplot2::ggplot
object, it can be combined with further layers and functionality from the ggplot2
package.
Usage
plot_raincloud(data, y, horizontal = FALSE, groups, point_size = 0.5, ...)
Arguments
data |
Data.frame (or tibble) |
y |
The unquoted name of the variable in data for which to create the raincloud plot |
horizontal |
(logical) change the orientation of the plot |
groups |
An unquoted name of grouping variable in data (ideally a factor) |
point_size |
Size of the jittered points |
... |
Other arguments, passed to ggplot(aes(...)) |
Value
An object of class gg
, i.e. a ggplot
object from the ggplot2
package
Source
Allen M, Poggiali D, Whitaker K et al. Raincloud plots: a multi-platform tool for robust data visualization. Wellcome Open Res 2019, 4:63 (doi:10.12688/wellcomeopenres.15191.1)
See Also
ggplot2::ggplot()
for information about ggplot objects, ggplot2::theme()
for information about changing various aspects of the plot, and ggplot2::facet_wrap()
and ggplot2::facet_grid()
for creating multiple raincloud plots for different levels of grouping factors beyond those specified in groups
.
Examples
data(anchoring)
plot_raincloud(anchoring,y=everest_feet)
plot_raincloud(anchoring,y=everest_feet,groups=anchor)
plot_raincloud(anchoring,y=everest_feet,groups=anchor) +
ggplot2::facet_wrap(~us_or_international) +
ggplot2::ylab("How high is Mount Everest (in feet)?")