diff --git a/NEWS.md b/NEWS.md index 9de0a85eee..f3ab472b5a 100644 --- a/NEWS.md +++ b/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 diff --git a/R/position-stack.r b/R/position-stack.r index e54de07451..0466a84919 100644 --- a/R/position-stack.r +++ b/R/position-stack.r @@ -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] diff --git a/tests/testthat/test-position-stack.R b/tests/testthat/test-position-stack.R index 313dae16a5..f3be540a16 100644 --- a/tests/testthat/test-position-stack.R +++ b/tests/testthat/test-position-stack.R @@ -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)) +})