mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2025-09-12 09:59:39 +02:00
29 lines
697 B
R
29 lines
697 B
R
|
#' 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")
|
||
|
plot_ridge <- function(data, x, y, z = NULL, ...) {
|
||
|
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() +
|
||
|
ggplot2::theme(legend.position = "none") |> rempsyc:::theme_apa()
|
||
|
})
|
||
|
|
||
|
patchwork::wrap_plots(out)
|
||
|
}
|