Skip to content

Commit b5e3494

Browse files
authored
Do not change order of positive and negative values in PositionStack (fixes #3390) (#3471)
1 parent a1be3d0 commit b5e3494

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

R/position-stack.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ PositionStack <- ggproto("PositionStack", Position,
195195
)
196196
}
197197

198-
rbind(neg, pos)
198+
rbind(neg, pos)[match(seq_len(nrow(data)), c(which(negative), which(!negative))),]
199199
}
200200
)
201201

tests/testthat/test-position-stack.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ test_that("negative and positive values are handled separately", {
2121
p <- ggplot(df, aes(x, y, fill = factor(g))) + geom_col()
2222
dat <- layer_data(p)
2323

24-
expect_equal(dat$ymin[dat$x == 1], c(-1, 0, 1))
25-
expect_equal(dat$ymax[dat$x == 1], c(0, 1, 2))
24+
expect_equal(dat$ymin[dat$x == 1], c(0, -1, 1))
25+
expect_equal(dat$ymax[dat$x == 1], c(1, 0, 2))
2626

27-
expect_equal(dat$ymin[dat$x == 2], c(-3, 0))
28-
expect_equal(dat$ymax[dat$x == 2], c(0, 2))
27+
expect_equal(dat$ymin[dat$x == 2], c(0, -3))
28+
expect_equal(dat$ymax[dat$x == 2], c(2, 0))
2929
})
3030

3131
test_that("can request reverse stacking", {
@@ -36,7 +36,7 @@ test_that("can request reverse stacking", {
3636
p <- ggplot(df, aes(1, y, fill = g)) +
3737
geom_col(position = position_stack(reverse = TRUE))
3838
dat <- layer_data(p)
39-
expect_equal(dat$ymin, c(-2, -3, 0, 2))
39+
expect_equal(dat$ymin, c(-2, 0, -3, 2))
4040
})
4141

4242
test_that("data with no extent is stacked correctly", {

0 commit comments

Comments
 (0)