File: test-ggplot-step.R

package info (click to toggle)
r-cran-plotly 4.10.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,636 kB
  • sloc: javascript: 195,272; sh: 24; makefile: 6
file content (50 lines) | stat: -rw-r--r-- 1,584 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50


# Dataset for test
oranges <- subset(Orange, Tree %in% c(1, 2))
# Line shapes available in plotly: "linear", "spline", "hv", "vh", "hvh", "vhv"

gg <- ggplot(oranges, aes(x=age, y=circumference,
                          group=Tree, colour=factor(Tree)))

test_that("direction hv is translated to shape=hv", {
  gg.hv <- gg + geom_step()
  L <- expect_doppelganger_built(gg.hv, "step-gg.hv")
  expect_equivalent(length(L$data), 2)
  expect_identical(L$data[[1]]$line$shape, "hv")
})

test_that("direction vh is translated to shape=vh", {
  gg.vh <- gg + geom_step(direction = "vh")
  L <- expect_doppelganger_built(gg.vh, "step-gg.vh")
  expect_equivalent(length(L$data), 2)
  expect_identical(L$data[[1]]$line$shape, "vh")
})

test_that("direction hvh is translated to shape=hvh", {
  gg.hvh <- gg + geom_step(direction="hvh")
  L <- expect_doppelganger_built(gg.hvh, "step-gg.hvh")
  expect_equivalent(length(L$data), 2)
  expect_identical(L$data[[1]]$line$shape, "hvh")
})

test_that("direction vhv is translated to shape=vhv", {
  gg.vhv <- gg + geom_step(direction="vhv")
  L <- expect_doppelganger_built(gg.vhv, "step-gg.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")
})