From c406fec4e33ce22efc0e32942ad8653b7e815479 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 2 Oct 2025 12:00:56 +0200 Subject: [PATCH 1/3] Remove oob-padding silently --- R/stat-align.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/stat-align.R b/R/stat-align.R index 23d0489396..7278773cf3 100644 --- a/R/stat-align.R +++ b/R/stat-align.R @@ -73,6 +73,13 @@ StatAlign <- ggproto( flipped_aes = flipped_aes ) flip_data(data_aligned, flipped_aes) + }, + + finish_layer = function(data, params) { + # Silently remove out-of-bounds padding vertices + var <- flipped_names(params$flipped_aes)$x + remove <- is.na(data[[var]]) & (data$align_padding %||% FALSE) + vec_slice(data, !remove) } ) From fec2cab3dcdf7d2412e3dd99ba441faaf5cedf59 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 2 Oct 2025 12:02:58 +0200 Subject: [PATCH 2/3] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 3e92547b2a..e0c0d8b22b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ ### Bug fixes +* Out-of-bounds datapoints used as padding by `stat_align()` now get removed + silently rather than verbosely (@teunbrand, #6667) * Fixed regression where `draw_key_rect()` stopped using `fill` colours (@mitchelloharawild, #6609). * Fixed regression where `scale_{x,y}_*()` threw an error when an expression From 797510c4b29d0dc42ba8f8a449a1740f11c9fa03 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 2 Oct 2025 12:08:03 +0200 Subject: [PATCH 3/3] add test --- tests/testthat/test-stat-align.R | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/testthat/test-stat-align.R b/tests/testthat/test-stat-align.R index 457992e747..c85fbc07ae 100644 --- a/tests/testthat/test-stat-align.R +++ b/tests/testthat/test-stat-align.R @@ -50,3 +50,24 @@ test_that("alignment adjusts per panel", { expect_equal(diff(ld$x[1:2]), 1e-3, tolerance = 1e-4) }) + +test_that("out-of-bounds padding is removed (#6667)", { + df <- data_frame0( + g = rep(c("a", "b"), each = 3L), + x = c(1, 3, 5, 2, 4, 6), + y = c(2, 5, 1, 3, 6, 7) + ) + p <- ggplot(df, aes(x, y, fill = g)) + geom_area() + ld <- layer_data(p) + expect_equal(sum(ld$align_padding), 4) + # The first and last datapoints should be padding + expect_equal(ld$align_padding[c(1, nrow(ld))], c(TRUE, TRUE)) + + + ld <- layer_data( + p + scale_x_continuous(limits = range(df$x), expand = c(0, 0)) + ) + expect_equal(sum(ld$align_padding), 2) + # The first and last datapoints should not be padding + expect_equal(ld$align_padding[c(1, nrow(ld))], c(FALSE, FALSE)) +})