Skip to content

Commit aa9dcb7

Browse files
authored
Fix ordering of lines in stat_ecdf() (#2065)
1 parent 35f9039 commit aa9dcb7

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* `ggplotly()` now supports the `{ggalluvial}` package. (#2061, @moutikabdessabour)
66
* `ggplotly()` does not issue warnings with `options(warnPartialMatchArgs = TRUE)` any longer. (#2046, @bersbersbers)
77

8+
## Bug fixes
9+
10+
* `ggplotly()` now converts `stat_ecdf()` properly. (#2065)
11+
812
# 4.10.0
913

1014
## Breaking changes in JavaScript API

R/layers2traces.R

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ to_basic.GeomLine <- function(data, prestats_data, layout, params, p, ...) {
252252

253253
#' @export
254254
to_basic.GeomStep <- function(data, prestats_data, layout, params, p, ...) {
255+
data <- data[order(data[["x"]]), ]
255256
prefix_class(data, "GeomPath")
256257
}
257258

tests/testthat/test-ggplot-step.R

+14
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,17 @@ test_that("direction vhv is translated to shape=vhv", {
3434
expect_equivalent(length(L$data), 2)
3535
expect_identical(L$data[[1]]$line$shape, "vhv")
3636
})
37+
38+
39+
test_that("`stat_ecdf` renders correctly", {
40+
df <- data.frame(
41+
x = c(rnorm(100, 0, 3), rnorm(100, 0, 10)),
42+
g = gl(2, 100)
43+
)
44+
45+
p <- ggplot(df, aes(x)) + stat_ecdf(geom = "step")
46+
expect_doppelganger(ggplotly(p), "step-ecdf")
47+
48+
p <- ggplot(df, aes(x, colour = g)) + stat_ecdf()
49+
expect_doppelganger(ggplotly(p), "step-ecdf-multiple")
50+
})

0 commit comments

Comments
 (0)