Skip to content
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
2 changes: 1 addition & 1 deletion R/position-stack.r
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ PositionStack <- ggproto("PositionStack", Position,
)
}

rbind(neg, pos)
rbind(neg, pos)[match(seq_len(nrow(data)), c(which(negative), which(!negative))),]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see immediately that this is always correct. Can there be problems with NAs? Or will NAs never reach this point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An NA value in ymax is pretty nonsensical and would also have broken the previous code. I can put in some guarding if you’d like nonetheless

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion either way. Just make sure to look into why the CI builds fail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failures are due to the downstream changes in sf, which have been fixed in master but not yet merged into the v3.2.1-rc branch

}
)

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-position-stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ test_that("negative and positive values are handled separately", {
p <- ggplot(df, aes(x, y, fill = factor(g))) + geom_col()
dat <- layer_data(p)

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

expect_equal(dat$ymin[dat$x == 2], c(-3, 0))
expect_equal(dat$ymax[dat$x == 2], c(0, 2))
expect_equal(dat$ymin[dat$x == 2], c(0, -3))
expect_equal(dat$ymax[dat$x == 2], c(2, 0))
})

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

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