View source: R/create_density_ridge_plot.R
create_density_ridge_plot | R Documentation |
Function creates ggplot2 based density plots stacked vertically (also known as ridge or raincloud plots).
The function's density arguments mirror most of the arguments available
from density
for the Kernel Density Estimation (KDE). See the density
help page
for more information.
create_density_ridge_plot(
df,
variables,
plot_heights = 3.5,
plot_widths = 24,
bw = "nrd0",
adjust = 1,
kernel = "gaussian",
n = 512,
na.rm = TRUE,
title = NULL,
title_fontsz = 14,
x_title = NULL,
rot_x_tic_angle = 0,
density_size = 1,
density_color = "black",
density_fill = "gray",
density_alpha = 0.4,
x_limits = NULL,
x_major_breaks = waiver(),
x_minor_breaks = waiver(),
x_labels = waiver(),
y_limits = NULL,
y_major_breaks = waiver(),
y_minor_breaks = waiver(),
y_show_axis = FALSE,
axis_text_size = 11,
display_plot = TRUE
)
df |
The source data frame from which the densities are plotted. |
variables |
A vector that names the x axis variables from |
plot_heights |
A numeric that sets the plot height in centimeters for each variable in |
plot_widths |
A numeric that sets the plot width in centimeters for each variable in |
bw |
A string or numeric that sets the smoothing bandwidth to be used with the KDE function. |
adjust |
A numeric that adjusts |
kernel |
A string that set the type of Kernel Density Estimation (KDE). Acceptable values are "gaussian", "rectangular", "triangular", "epanechnikov", "biweight", "cosine" or "optcosine". |
n |
The number of equally spaced points at which the density is to be estimated. This should be a power of two. |
na.rm |
A logical which if |
title |
A string that sets the overall title. |
title_fontsz |
A numeric that sets the title's font size. The default is 14. |
x_title |
A string that sets the x axis title. If NULL (the default) then the x axis title does not appear. |
rot_x_tic_angle |
A numeric that sets the angle of rotation for the x tic labels. When x tic labels are long, a value of 40 for this argument usually works well. |
density_size |
A numeric that sets the density line width. |
density_color |
A string that sets the color for the density line. |
density_fill |
A string that sets the color for the density fill. |
density_alpha |
A numeric that sets the alpha value for |
x_limits |
A numeric 2 element vector or function that sets the minimum and maximum for the x axis. Use NA to refer to the existing minimum and maximum. |
x_major_breaks |
A numeric vector or function that sets the major tic locations along the x axis. |
x_minor_breaks |
A numeric vector or function that sets the minor tic locations along the x axis. |
x_labels |
A character vector or function giving x axis tic labels. Must be the same length as |
y_limits |
A numeric 2 element vector or function that sets the minimum and maximum for the y axis. Use NA to refer to the existing minimum and maximum. |
y_major_breaks |
A numeric vector or function that sets the major tic locations along the y axis. |
y_minor_breaks |
A numeric vector or function that sets the minor tic locations along the y axis. |
y_show_axis |
A logical which if TRUE will display the y-axis density for each variable. |
axis_text_size |
A numeric that sets the font size along the axis'. Default is 11. |
display_plot |
A logical that if TRUE will display the plot. |
if display_plot
is TRUE then the plots will be displayed. If display_plot
is FALSE then
the function returns a plot object which can be displayed from the console by entering
grid::grid.draw(plot object)
A TableGrob object if display_plot
is FALSE.
Rick Dean
Micah Allen,Davide Poggiali,Kirstie Whitaker,Tom Rhys Marshall, Jordy van Langen,Rogier A. Kievit (2021) Raincloud plots: a multi-platform tool for robust data visualization: version 2
Joachim Schork (2021) Ridgeline Plots in R (3 Examples)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.