Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ridgeline plot from ggridges. [WIP] #258

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Suggests:
packagedocs (>= 0.4.0),
rmarkdown,
roxygen2,
testthat
testthat,
ggridges
Roxygen: list(wrap = FALSE)
RoxygenNote: 6.0.1
VignetteBuilder: packagedocs
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(ggally_box_no_facet)
export(ggally_cor)
export(ggally_density)
export(ggally_densityDiag)
export(ggally_density_ridges)
export(ggally_denstrip)
export(ggally_diagAxis)
export(ggally_dot)
Expand Down
30 changes: 30 additions & 0 deletions R/gg-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -1329,3 +1329,33 @@ ggally_na <- function(data = NULL, mapping = NULL, size = 10, color = "grey20",
ggally_naDiag <- function(...) {
ggally_na(...)
}

#' Create a ridgeline plot.
#'
#' `ggally_density_ridges` arranges multiple density plots in a staggered fashion, as in the cover of the famous Joy Division album Unknown Pleasures.
#'
#' @param data The data set used.
#' @param mapping The aesthetics used.
#' @param ... Other parameters passed on to \code{\link[ggridges]{geom_density_ridges}}.
#'
#' @examples
#' data(iris)
#' ggpairs(iris, lower = list("combo" = ggally_density_ridges))
#' ggpairs(iris, lower = list("combo" = ggally_density_ridges, mapping = ggplot2::aes(color = Species)))
#' ggpairs(iris, lower = list("combo" = wrap(ggally_density_ridges, rel_min_height = 0.01), mapping = ggplot2::aes(color = Species)))
#'
#' @author Jens Preussner \email{jens.preussner@@mpi-bn.mpg.de}
#' @export
ggally_density_ridges <- function(data, mapping, ...) {
require_pkgs("ggridges")
horizontal <- is_horizontal(data, mapping)

if (!horizontal) {
mapping <- mapping_swap_x_y(mapping)
}

mapping <- mapping_color_to_fill(mapping)

ggplot2::ggplot(data) +
ggridges::geom_density_ridges2(mapping, ...)
}
28 changes: 28 additions & 0 deletions man/ggally_density_ridges.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.