File: test-stat-ecdf.R

package info (click to toggle)
r-cran-ggplot2 3.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,748 kB
  • sloc: sh: 15; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 761 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
test_that("stat_ecdf works in both directions", {
  p <- ggplot(mpg, aes(hwy)) + stat_ecdf()
  x <- layer_data(p)
  expect_false(x$flipped_aes[1])

  p <- ggplot(mpg, aes(y = hwy)) + stat_ecdf()
  y <- layer_data(p)
  expect_true(y$flipped_aes[1])

  x$flipped_aes <- NULL
  y$flipped_aes <- NULL
  expect_identical(x, flip_data(y, TRUE)[,names(x)])

  p <- ggplot(mpg) + stat_ecdf()
  expect_snapshot_error(ggplot_build(p))
})

# See #5113 and #5112
test_that("stat_ecdf responds to axis transformations", {
  n <- 4
  answer <- c(seq(0, 1, length.out = n + 1), 1)
  p <- ggplot(data_frame0(x = seq_len(n)), aes(x)) + stat_ecdf()

  ld <- layer_data(p)
  expect_equal(ld$y, answer)

  ld <- layer_data(p + scale_y_sqrt())
  expect_equal(ld$y, sqrt(answer))
})