diff --git a/NEWS.md b/NEWS.md index 6b6cc439ff..a279f12f03 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()` and `position_jitterdodge()` now have a `reverse` argument (@teunbrand, #3610) * `coord_radial(r.axis.inside)` can now take a numeric value to control 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, 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, ...