Skip to content

Commit d1ecd03

Browse files
ikosmidispaleolimbot
authored andcommitted
Allow use of position_stack() when ymax is NA (#3416, fixes #2709)
1 parent a7c1138 commit d1ecd03

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

NEWS.md

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

3+
* stacking text when calculating the labels and the y axis with
4+
`stat_summary()` now works (@ikosmidis, #2709)
5+
36
* Allowed reversing of discrete scales by re-writing `get_limits()` (@AnneLyng, #3115)
47

58
* Added `stat_contour_filled()` and `geom_contour_filled()`, which compute

R/position-stack.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ PositionStack <- ggproto("PositionStack", Position,
177177
}
178178

179179
negative <- data$ymax < 0
180+
negative[is.na(negative)] <- FALSE
181+
180182
neg <- data[negative, , drop = FALSE]
181183
pos <- data[!negative, , drop = FALSE]
182184

tests/testthat/test-position-stack.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ test_that("data with no extent is stacked correctly", {
5252
expect_equal(layer_data(p0)$y, c(-75, -115))
5353
expect_equal(layer_data(p1)$y, c(0, -75))
5454
})
55+
56+
test_that("position_stack() can stack correctly when ymax is NA", {
57+
df <- data_frame(x = c(1, 1), y = c(1, 1))
58+
p <- ggplot(df, aes(x, y, ymax = NA_real_)) + geom_point(position = "stack")
59+
expect_equal(layer_data(p)$y, c(1, 2))
60+
})

0 commit comments

Comments
 (0)