Skip to content

Commit 01eff23

Browse files
authored
Add geom_step(orientation) argument (#5937)
* add `orientiation` to `geom_step()` * add news bullet * document
1 parent b11d574 commit 01eff23

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ggplot2 (development version)
22

3+
* `geom_step()` now supports the `orientation` argument (@teunbrand, #5936).
34
* `position_dodge()` and `position_jitterdodge()` now have a `reverse` argument
45
(@teunbrand, #3610)
56
* `coord_radial(r.axis.inside)` can now take a numeric value to control

R/geom-path.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ GeomLine <- ggproto("GeomLine", GeomPath,
305305
#' @rdname geom_path
306306
geom_step <- function(mapping = NULL, data = NULL, stat = "identity",
307307
position = "identity", direction = "hv",
308-
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) {
308+
na.rm = FALSE, orientation = NA, show.legend = NA,
309+
inherit.aes = TRUE, ...) {
309310
layer(
310311
data = data,
311312
mapping = mapping,
@@ -316,6 +317,7 @@ geom_step <- function(mapping = NULL, data = NULL, stat = "identity",
316317
inherit.aes = inherit.aes,
317318
params = list2(
318319
direction = direction,
320+
orientation = orientation,
319321
na.rm = na.rm,
320322
...
321323
)
@@ -328,11 +330,21 @@ geom_step <- function(mapping = NULL, data = NULL, stat = "identity",
328330
#' @export
329331
#' @include geom-path.R
330332
GeomStep <- ggproto("GeomStep", GeomPath,
333+
setup_params = function(data, params) {
334+
params$flipped_aes <- has_flipped_aes(data, params, ambiguous = TRUE)
335+
params
336+
},
337+
extra_params = c("na.rm", "orientation"),
331338
draw_panel = function(data, panel_params, coord,
332339
lineend = "butt", linejoin = "round", linemitre = 10,
333340
arrow = NULL, arrow.fill = NULL,
334-
direction = "hv") {
341+
direction = "hv", flipped_aes = FALSE) {
342+
data <- flip_data(data, flipped_aes)
343+
if (isTRUE(flipped_aes)) {
344+
direction <- switch(direction, hv = "vh", vh = "hv", direction)
345+
}
335346
data <- dapply(data, "group", stairstep, direction = direction)
347+
data <- flip_data(data, flipped_aes)
336348
GeomPath$draw_panel(
337349
data, panel_params, coord,
338350
lineend = lineend, linejoin = linejoin, linemitre = linemitre,

man/geom_path.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)