File: test-geom-rule.R

package info (click to toggle)
r-cran-ggplot2 3.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,184 kB
  • sloc: sh: 15; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download
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
context("geom_rule")
# tests for geom_vline, geom_hline & geom_abline

df <- data_frame(x = 1:3, y = 3:1)
p <- ggplot(df, aes(x, y)) + geom_point()
p_col <- ggplot(df, aes(x, y, colour = factor(x))) + geom_point()

test_that("setting parameters makes one row df", {
  b <- p + geom_hline(yintercept = 1.5)
  expect_equal(layer_data(b, 2)$yintercept, 1.5)

  b <- p + geom_vline(xintercept = 1.5)
  expect_equal(layer_data(b, 2)$xintercept, 1.5)

  b <- p + geom_abline()
  expect_equal(layer_data(b, 2)$intercept, 0)
  expect_equal(layer_data(b, 2)$slope, 1)

  b <- p + geom_abline(slope = 0, intercept = 1)
  expect_equal(layer_data(b, 2)$intercept, 1)
  expect_equal(layer_data(b, 2)$slope, 0)
})

test_that("setting aesthetics generates one row for each input row", {
  b <- p + geom_hline(aes(yintercept = 1.5))
  expect_equal(layer_data(b, 2)$yintercept, rep(1.5, 3))

  b <- p + geom_vline(aes(xintercept = 1.5))
  expect_equal(layer_data(b, 2)$xintercept, rep(1.5, 3))

  b <- p + geom_abline(aes(slope = 0, intercept = 1))
  expect_equal(layer_data(b, 2)$intercept, rep(1, 3))
  expect_equal(layer_data(b, 2)$slope, rep(0, 3))
})