Skip to content

Commit

Permalink
Allow use of position_stack() when ymax is NA (#3416, fixes #2709)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikosmidis authored and paleolimbot committed Jul 17, 2019
1 parent a7c1138 commit d1ecd03
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
@@ -1,5 +1,8 @@
# ggplot2 (development version)

* stacking text when calculating the labels and the y axis with
`stat_summary()` now works (@ikosmidis, #2709)

* Allowed reversing of discrete scales by re-writing `get_limits()` (@AnneLyng, #3115)

* Added `stat_contour_filled()` and `geom_contour_filled()`, which compute
Expand Down
2 changes: 2 additions & 0 deletions R/position-stack.r
Expand Up @@ -177,6 +177,8 @@ PositionStack <- ggproto("PositionStack", Position,
}

negative <- data$ymax < 0
negative[is.na(negative)] <- FALSE

neg <- data[negative, , drop = FALSE]
pos <- data[!negative, , drop = FALSE]

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-position-stack.R
Expand Up @@ -52,3 +52,9 @@ test_that("data with no extent is stacked correctly", {
expect_equal(layer_data(p0)$y, c(-75, -115))
expect_equal(layer_data(p1)$y, c(0, -75))
})

test_that("position_stack() can stack correctly when ymax is NA", {
df <- data_frame(x = c(1, 1), y = c(1, 1))
p <- ggplot(df, aes(x, y, ymax = NA_real_)) + geom_point(position = "stack")
expect_equal(layer_data(p)$y, c(1, 2))
})

0 comments on commit d1ecd03

Please sign in to comment.