#' Make a random stacked density plot
#' @param n_lines num how many density lines
#' @param n_rows num how many points (lower will give more variability)
#' @param n_colors num how many colors to use; defaults to `n_lines`
#' @param color_palette chr which color palette to use
#' @param palette_colors chr vector of colors from color palette, usually generated by `get_palette_colors()`
#' @param ... other arguments passed on to `layer()`
#' @return `ggplot` object
#' @export
make_random_stacked_density <- function(n_lines = 9,
n_rows = 1000,
n_colors = n_lines,
color_palette = NULL,
palette_colors = get_palette_colors(color_palette, n_colors),
...) {
df <- data.frame(
x = stats::runif(n_rows),
y = factor(sample(1:n_lines, n_rows, replace = TRUE))
)
gg <- ggplot2::ggplot(df, ggplot2::aes(x = x, group = y, fill = y)) +
ggplot2::geom_density(position = 'fill', ...) +
ggplot2::scale_fill_manual(values = palette_colors)
gg
return(gg)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.