From a2709d369babded6e00d25d8fc2945303bc2946b Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 28 Nov 2022 11:23:54 -0600 Subject: [PATCH 1/2] Close #2208: make ribbon_dat() a no-op if there is no data --- R/layers2traces.R | 1 + tests/testthat/test-ggplot-area.R | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/R/layers2traces.R b/R/layers2traces.R index dedd8d9d43..ac101519fc 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -1061,6 +1061,7 @@ make_error <- function(data, params, xy = "x") { # (note this function is also used for geom_smooth) ribbon_dat <- function(dat) { n <- nrow(dat) + if (n == 0) return(dat) o <- order(dat[["x"]]) o2 <- order(dat[["x"]], decreasing = TRUE) used <- c("x", "ymin", "ymax", "y") diff --git a/tests/testthat/test-ggplot-area.R b/tests/testthat/test-ggplot-area.R index bd0b10173c..acb1b3db8f 100644 --- a/tests/testthat/test-ggplot-area.R +++ b/tests/testthat/test-ggplot-area.R @@ -68,3 +68,18 @@ test_that("traces are ordered correctly in geom_area", { } }) + +test_that("Can handle an 'empty' geom_area()", { + p <- ggplot(data.frame(x = 1, y = 1), aes(x, y)) + + geom_area() + + geom_point() + + l <- ggplotly(p)$x + + expect_length(l$data, 2) + + expect_false(l$data[[1]]$visible) + expect_true(l$data[[2]]$x == 1) + expect_true(l$data[[2]]$y == 1) + expect_true(l$data[[2]]$mode == "markers") +}) From a3ee6943214ca0b316493abcecf807662b0f280b Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 28 Nov 2022 11:25:35 -0600 Subject: [PATCH 2/2] Update news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 478263a0a3..ac86dabcdc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # 4.10.1.9000 +## Bug fixes +* `ggplotly()` no longer errors given a `geom_area()` with 1 or less data points (error introduced by new behavior in ggplot2 v3.4.0). (#2209) # 4.10.1