We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
stat_align()
1 parent f147aaf commit 367ade9Copy full SHA for 367ade9
NEWS.md
@@ -2,6 +2,8 @@
2
3
### Bug fixes
4
5
+* Out-of-bounds datapoints used as padding by `stat_align()` now get removed
6
+ silently rather than verbosely (@teunbrand, #6667)
7
* Fixed bug where `stat_bin(boundary)` was ignored (#6682).
8
* `geom_text()` and `geom_label()` accept expressions as the `label` aesthetic
9
(@teunbrand, #6638)
R/stat-align.R
@@ -73,6 +73,13 @@ StatAlign <- ggproto(
73
flipped_aes = flipped_aes
74
)
75
flip_data(data_aligned, flipped_aes)
76
+ },
77
+
78
+ finish_layer = function(data, params) {
79
+ # Silently remove out-of-bounds padding vertices
80
+ var <- flipped_names(params$flipped_aes)$x
81
+ remove <- is.na(data[[var]]) & (data$align_padding %||% FALSE)
82
+ vec_slice(data, !remove)
83
}
84
85
tests/testthat/test-stat-align.R
@@ -50,3 +50,24 @@ test_that("alignment adjusts per panel", {
50
expect_equal(diff(ld$x[1:2]), 1e-3, tolerance = 1e-4)
51
52
})
53
54
+test_that("out-of-bounds padding is removed (#6667)", {
55
+ df <- data_frame0(
56
+ g = rep(c("a", "b"), each = 3L),
57
+ x = c(1, 3, 5, 2, 4, 6),
58
+ y = c(2, 5, 1, 3, 6, 7)
59
+ )
60
+ p <- ggplot(df, aes(x, y, fill = g)) + geom_area()
61
+ ld <- layer_data(p)
62
+ expect_equal(sum(ld$align_padding), 4)
63
+ # The first and last datapoints should be padding
64
+ expect_equal(ld$align_padding[c(1, nrow(ld))], c(TRUE, TRUE))
65
66
67
+ ld <- layer_data(
68
+ p + scale_x_continuous(limits = range(df$x), expand = c(0, 0))
69
70
+ expect_equal(sum(ld$align_padding), 2)
71
+ # The first and last datapoints should not be padding
72
+ expect_equal(ld$align_padding[c(1, nrow(ld))], c(FALSE, FALSE))
+})
0 commit comments