2025-03-13 12:41:50 +01:00
|
|
|
#' Plot nice ridge plot
|
|
|
|
|
#'
|
|
|
|
|
#' @returns ggplot2 object
|
|
|
|
|
#' @export
|
|
|
|
|
#'
|
|
|
|
|
#' @name data-plots
|
|
|
|
|
#'
|
|
|
|
|
#' @examples
|
|
|
|
|
#' mtcars |>
|
|
|
|
|
#' default_parsing() |>
|
|
|
|
|
#' plot_ridge(x = "mpg", y = "cyl")
|
|
|
|
|
#' mtcars |> plot_ridge(x = "mpg", y = "cyl", z = "gear")
|
2026-03-24 12:04:54 +01:00
|
|
|
plot_ridge <- function(data, x, y, z = NULL, color.palette="viridis", ...) {
|
2025-03-13 12:41:50 +01:00
|
|
|
if (!is.null(z)) {
|
|
|
|
|
ds <- split(data, data[z])
|
|
|
|
|
} else {
|
|
|
|
|
ds <- list(data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out <- lapply(ds, \(.ds){
|
|
|
|
|
ggplot2::ggplot(.ds, ggplot2::aes(x = !!dplyr::sym(x), y = !!dplyr::sym(y), fill = !!dplyr::sym(y))) +
|
|
|
|
|
ggridges::geom_density_ridges() +
|
|
|
|
|
ggridges::theme_ridges() +
|
2026-03-24 12:04:54 +01:00
|
|
|
scale_fill_generate(palette=color.palette) +
|
2025-03-13 12:41:50 +01:00
|
|
|
ggplot2::theme(legend.position = "none") |> rempsyc:::theme_apa()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
patchwork::wrap_plots(out)
|
|
|
|
|
}
|