diff --git a/NEWS.md b/NEWS.md index 56775ea13a..b9dbd8e5ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,10 @@ * `ggplotly()` does not issue warnings with `options(warnPartialMatchArgs = TRUE)` any longer. (#2046, @bersbersbers) +## Bug fixes + +* `ggplotly()` now converts `stat_ecdf()` properly. (#2065) + # 4.10.0 ## Breaking changes in JavaScript API diff --git a/R/layers2traces.R b/R/layers2traces.R index 8ddd90c156..81fd4f7e17 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -252,6 +252,7 @@ to_basic.GeomLine <- function(data, prestats_data, layout, params, p, ...) { #' @export to_basic.GeomStep <- function(data, prestats_data, layout, params, p, ...) { + data <- data[order(data[["x"]]), ] prefix_class(data, "GeomPath") } diff --git a/tests/testthat/test-ggplot-step.R b/tests/testthat/test-ggplot-step.R index fc5fe6b7dc..500b30c1a0 100644 --- a/tests/testthat/test-ggplot-step.R +++ b/tests/testthat/test-ggplot-step.R @@ -34,3 +34,17 @@ test_that("direction vhv is translated to shape=vhv", { expect_equivalent(length(L$data), 2) expect_identical(L$data[[1]]$line$shape, "vhv") }) + + +test_that("`stat_ecdf` renders correctly", { + df <- data.frame( + x = c(rnorm(100, 0, 3), rnorm(100, 0, 10)), + g = gl(2, 100) + ) + + p <- ggplot(df, aes(x)) + stat_ecdf(geom = "step") + expect_doppelganger(ggplotly(p), "step-ecdf") + + p <- ggplot(df, aes(x, colour = g)) + stat_ecdf() + expect_doppelganger(ggplotly(p), "step-ecdf-multiple") +})