Skip to content

Commit a760ff6

Browse files
committed
Suppress default NA handling for geom_ribbon.
Fixes #1549
1 parent 3265e00 commit a760ff6

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555

5656
* `geom_path()` knows that "solid" (not just 1) represents a solid line (#1534).
5757

58+
* `geom_ribbon()` preserves missing values so they correctly generate a
59+
gap in the ribbon (#1549).
60+
5861
* `geom_histgram(bins = n)` now gives a histogram with `n` bins, not `n + 1`
5962
(#1487).
6063

R/geom-ribbon.r

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
6565

6666
draw_key = draw_key_polygon,
6767

68+
handle_na = function(data, params) {
69+
data
70+
},
71+
6872
draw_group = function(data, panel_scales, coord, na.rm = FALSE) {
6973
if (na.rm) data <- data[stats::complete.cases(data[c("x", "ymin", "ymax")]), ]
7074
data <- data[order(data$group, data$x), ]

tests/testthat/test-geom-ribbon.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
context("geom_ribbon")
2+
3+
test_that("NAs are not dropped from the data", {
4+
df <- data.frame(x = 1:5, y = c(1, 1, NA, 1, 1))
5+
6+
p <- ggplot(df, aes(x))+
7+
geom_ribbon(aes(ymin = y - 1, ymax = y + 1))
8+
9+
expect_equal(layer_data(p)$ymin, c(0, 0, NA, 0, 0))
10+
})

0 commit comments

Comments
 (0)