Skip to content

Commit aa383b4

Browse files
committed
Close #1377: fix ordering of lines in stat_ecdf()
1 parent 15807cf commit aa383b4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: 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

Diff for: 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)