Skip to content

Commit 0799463

Browse files
authored
Allow "lower" outline type in geom_ribbon and family (#3707)
1 parent 758bc59 commit 0799463

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

R/geom-ribbon.r

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#' @inheritParams layer
2323
#' @inheritParams geom_bar
2424
#' @param outline.type Type of the outline of the area; `"both"` draws both the
25-
#' upper and lower lines, `"upper"` draws the upper lines only. `"legacy"`
26-
#' draws a closed polygon around the area.
25+
#' upper and lower lines, `"upper"`/`"lower"` draws the either lines only.
26+
#' `"legacy"` draws a closed polygon around the area.
2727
#' @export
2828
#' @examples
2929
#' # Generate data
@@ -49,7 +49,7 @@ geom_ribbon <- function(mapping = NULL, data = NULL,
4949
show.legend = NA,
5050
inherit.aes = TRUE,
5151
outline.type = "both") {
52-
outline.type <- match.arg(outline.type, c("both", "upper", "legacy"))
52+
outline.type <- match.arg(outline.type, c("both", "upper", "lower", "legacy"))
5353

5454
layer(
5555
data = data,
@@ -158,6 +158,7 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
158158
munched_lines$id <- switch(outline.type,
159159
both = munched_lines$id + rep(c(0, max(ids, na.rm = TRUE)), each = length(ids)),
160160
upper = munched_lines$id + rep(c(0, NA), each = length(ids)),
161+
lower = munched_lines$id + rep(c(NA, 0), each = length(ids)),
161162
abort(glue("invalid outline.type: {outline.type}"))
162163
)
163164
g_lines <- polylineGrob(
@@ -180,7 +181,7 @@ geom_area <- function(mapping = NULL, data = NULL, stat = "identity",
180181
position = "stack", na.rm = FALSE, orientation = NA,
181182
show.legend = NA, inherit.aes = TRUE, ...,
182183
outline.type = "upper") {
183-
outline.type <- match.arg(outline.type, c("both", "upper", "legacy"))
184+
outline.type <- match.arg(outline.type, c("both", "upper", "lower", "legacy"))
184185

185186
layer(
186187
data = data,

man/geom_ribbon.Rd

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

tests/testthat/test-geom-ribbon.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test_that("outline.type option works", {
3434

3535
g_ribbon_default <- layer_grob(p + geom_ribbon())[[1]]
3636
g_ribbon_upper <- layer_grob(p + geom_ribbon(outline.type = "upper"))[[1]]
37+
g_ribbon_lower <- layer_grob(p + geom_ribbon(outline.type = "lower"))[[1]]
3738
g_ribbon_legacy <- expect_warning(
3839
layer_grob(p + geom_ribbon(outline.type = "legacy"))[[1]],
3940
'outline.type = "legacy" is only for backward-compatibility and might be removed eventually',
@@ -51,6 +52,11 @@ test_that("outline.type option works", {
5152
expect_s3_class(g_ribbon_upper$children[[1]]$children[[2]], "polyline")
5253
expect_equal(g_ribbon_upper$children[[1]]$children[[2]]$id, rep(c(1L, NA), each = 4))
5354

55+
# lower
56+
expect_s3_class(g_ribbon_lower$children[[1]]$children[[1]], "polygon")
57+
expect_s3_class(g_ribbon_lower$children[[1]]$children[[2]], "polyline")
58+
expect_equal(g_ribbon_lower$children[[1]]$children[[2]]$id, rep(c(NA, 1L), each = 4))
59+
5460
# legacy
5561
expect_s3_class(g_ribbon_legacy$children[[1]], "polygon")
5662

0 commit comments

Comments
 (0)