Skip to content

Position stack+text geom #3416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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))
})