From a11c96ac58bdb546427fd5efbea2029871aa77ba Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 7 Jun 2024 11:13:59 +0200 Subject: [PATCH 1/3] add `orientiation` to `geom_step()` --- R/geom-path.R | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/R/geom-path.R b/R/geom-path.R index fe4359fb08..9b737267ca 100644 --- a/R/geom-path.R +++ b/R/geom-path.R @@ -305,7 +305,8 @@ GeomLine <- ggproto("GeomLine", GeomPath, #' @rdname geom_path geom_step <- function(mapping = NULL, data = NULL, stat = "identity", position = "identity", direction = "hv", - na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) { + na.rm = FALSE, orientation = NA, show.legend = NA, + inherit.aes = TRUE, ...) { layer( data = data, mapping = mapping, @@ -316,6 +317,7 @@ geom_step <- function(mapping = NULL, data = NULL, stat = "identity", inherit.aes = inherit.aes, params = list2( direction = direction, + orientation = orientation, na.rm = na.rm, ... ) @@ -328,11 +330,21 @@ geom_step <- function(mapping = NULL, data = NULL, stat = "identity", #' @export #' @include geom-path.R GeomStep <- ggproto("GeomStep", GeomPath, + setup_params = function(data, params) { + params$flipped_aes <- has_flipped_aes(data, params, ambiguous = TRUE) + params + }, + extra_params = c("na.rm", "orientation"), draw_panel = function(data, panel_params, coord, lineend = "butt", linejoin = "round", linemitre = 10, arrow = NULL, arrow.fill = NULL, - direction = "hv") { + direction = "hv", flipped_aes = FALSE) { + data <- flip_data(data, flipped_aes) + if (isTRUE(flipped_aes)) { + direction <- switch(direction, hv = "vh", vh = "hv", direction) + } data <- dapply(data, "group", stairstep, direction = direction) + data <- flip_data(data, flipped_aes) GeomPath$draw_panel( data, panel_params, coord, lineend = lineend, linejoin = linejoin, linemitre = linemitre, From ac596193e6f2e87bf841411a11b492bd23864c02 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 7 Jun 2024 11:21:38 +0200 Subject: [PATCH 2/3] add news bullet --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 583017fc33..5392b4ad61 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # ggplot2 (development version) +* `geom_step()` now supports the `orientation` argument (@teunbrand, #5936). * `position_dodge(preserve = "single")` now handles multi-row geoms better, such as `geom_violin()` (@teunbrand based on @clauswilke's work, #2801). * `position_jitterdodge()` now dodges by `group` (@teunbrand, #3656) From 122e0e3e65035475dc7f73d01e704fcad37b3812 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 7 Jun 2024 11:21:38 +0200 Subject: [PATCH 3/3] document --- NEWS.md | 1 + man/geom_path.Rd | 1 + 2 files changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 583017fc33..5392b4ad61 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # ggplot2 (development version) +* `geom_step()` now supports the `orientation` argument (@teunbrand, #5936). * `position_dodge(preserve = "single")` now handles multi-row geoms better, such as `geom_violin()` (@teunbrand based on @clauswilke's work, #2801). * `position_jitterdodge()` now dodges by `group` (@teunbrand, #3656) diff --git a/man/geom_path.Rd b/man/geom_path.Rd index 00a3ef8e5a..239b7dc0c6 100644 --- a/man/geom_path.Rd +++ b/man/geom_path.Rd @@ -41,6 +41,7 @@ geom_step( position = "identity", direction = "hv", na.rm = FALSE, + orientation = NA, show.legend = NA, inherit.aes = TRUE, ...