From aa383b49c23c569286855ac7fe748357fc0ed2b9 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 2 Nov 2021 10:32:11 -0500 Subject: [PATCH 1/2] Close #1377: fix ordering of lines in stat_ecdf() --- R/layers2traces.R | 1 + tests/testthat/test-ggplot-step.R | 14 ++++++++++++++ 2 files changed, 15 insertions(+) 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") +}) From 2da3eca486adcac2c4a6d7d175d2316f8d0bce0a Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 2 Nov 2021 10:51:18 -0500 Subject: [PATCH 2/2] Update news --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) 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