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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* Fixed regression where `position_stack(vjust)` was ignored when there are
only single groups (#6692)
* Fixed bug where `NA` handling in `geom_path()` was ignoring panels (@teunbrand, #6533)
* Logical values for the linetype aesthetic will be interpreted numerically,
so that `linetype = FALSE` becomes 0/'blank' and `linetype = TRUE` becomes
Expand Down
4 changes: 3 additions & 1 deletion R/position-stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ PositionStack <- ggproto("PositionStack", Position,
flipped_aes <- has_flipped_aes(data)
data <- flip_data(data, flipped_aes)
var <- self$var %||% stack_var(data)
if (!vec_duplicate_any(data$x) && !isTRUE(self$fill)) {
if (!vec_duplicate_any(data$x) &&
!isTRUE(self$fill) &&
all(self$vjust == 1)) {
# We skip stacking when all data have different x positions so that
# there is nothing to stack
var <- NULL
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-position-stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ test_that("data with no extent is stacked correctly", {
y = c(-40, -75),
group = letters[1:2]
)
base <- ggplot(df, aes(x, y, group = group))
p0 <- base + geom_text(aes(label = y), position = position_stack(vjust = 0))
p1 <- base + geom_text(aes(label = y), position = position_stack(vjust = 1))
base <- ggplot(df, aes(x, y, group = group, label = y))
p0 <- base + geom_text(position = position_stack(vjust = 0))
p1 <- base + geom_text(position = position_stack(vjust = 1))
p2 <- base + geom_text(aes(group = 1L), position = position_stack(vjust = 0.5))

expect_equal(get_layer_data(p0)$y, c(-115, -75))
expect_equal(get_layer_data(p1)$y, c(-75, 0))
expect_equal(get_layer_data(p2)$y, c(df$y[1] / 2, df$y[1] + df$y[2] / 2))
})

test_that("position_stack() can stack correctly when ymax is NA", {
Expand Down