tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.39k stars 2k forks source link

Add `geom_step(orientation)` argument #5937

Open teunbrand opened 4 weeks ago

teunbrand commented 4 weeks ago

This PR aims to fix #5936.

Briefly, it adds the orientation argument to geom_step(). If orientation = "y", stairsteps are constructed vertically.

In the example below, recall that the steps go from top to bottom, so direction = "hv" first does the horizontal step, then the vertical one (and vice versa for direciton = "vh").

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

recent <- economics[economics$date > as.Date("2013-01-01"), ]
ggplot(recent, aes(date, unemploy)) +
  geom_point(shape = 21, size = 3, fill = "white") +
  geom_step(aes(colour = "hv"), orientation = "y", direction = "hv") +
  geom_step(aes(colour = "vh"), orientation = "y", direction = "vh") +
  geom_step(aes(colour = "mid"),orientation = "y", direction = "mid")

Created on 2024-06-07 with reprex v2.1.0