File: test-geom-hline-vline-abline.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 (121 lines) | stat: -rw-r--r-- 3,261 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
context("geom-hline-vline-abline")


# Visual tests ------------------------------------------------------------

test_that("check h/v/abline transformed on basic projections", {
  dat <- data_frame(x = LETTERS[1:5], y = 1:5)
  plot <- ggplot(dat, aes(x, y)) +
    geom_col(width = 1) +
    geom_point() +
    geom_vline(xintercept = 3, colour = "red") +
    geom_hline(yintercept = 3, colour = "blue") +
    geom_abline(intercept = 0, slope = 1, colour = "purple") +
    labs(x = NULL, y = NULL) +
    coord_cartesian(expand = FALSE)

  expect_doppelganger(
    "cartesian lines intersect mid-bars",
    plot
  )
  expect_doppelganger(
    "flipped lines intersect mid-bars",
    plot + coord_flip()
  )
  expect_doppelganger(
    "polar lines intersect mid-bars",
    plot + coord_polar()
  )
})

test_that("curved lines in map projections", {
  nz <- subset(map_data("nz"), region == "North.Island ")
  nzmap <- ggplot(nz, aes(long, lat, group = group)) +
    geom_path() +
    geom_hline(yintercept = -38.6) + # roughly Taupo
    geom_vline(xintercept = 176) +
    coord_map()

  expect_doppelganger("straight lines in mercator",
    nzmap
  )
  expect_doppelganger("lines curved in azequalarea",
    nzmap + coord_map(projection = 'azequalarea', orientation = c(-36.92, 174.6, 0))
  )
})

# Warning tests ------------------------------------------------------------

test_that("warn_overwritten_args() produces gramatically correct error messages", {
  expect_warning(
    warn_overwritten_args("fun_test", "is_overwritten", "provided"),
    "fun_test: Ignoring `is_overwritten` because `provided` was provided."
  )
  expect_warning(
    warn_overwritten_args("fun_test", "is_overwritten", c("provided1", "provided2")),
    "fun_test: Ignoring `is_overwritten` because `provided1` and/or `provided2` were provided."
  )
  expect_warning(
    warn_overwritten_args("fun_test", "is_overwritten", c("provided1", "provided2", "provided3")),
    "fun_test: Ignoring `is_overwritten` because `provided1`, `provided2`, and/or `provided3` were provided."
  )
})

test_that("Warning if a supplied mapping is going to be overwritten", {

  expect_warning(
    geom_vline(xintercept = 3, aes(colour = colour)),
    "Ignoring `mapping`"
  )

  expect_warning(
    geom_hline(yintercept = 3, aes(colour = colour)),
    "Ignoring `mapping`"
  )

  expect_warning(
    geom_abline(intercept = 3, aes(colour = colour)),
    "Ignoring `mapping`"
  )

  expect_warning(
    geom_abline(intercept = 3, slope = 0.5, aes(colour = colour)),
    "Ignoring `mapping`"
  )

  expect_warning(
    geom_abline(slope = 0.5, aes(colour = colour)),
    "Ignoring `mapping`"
  )
})


test_that("Warning if supplied data is going to be overwritten", {

  sample_data <- data_frame(x = 1)

  expect_warning(
    geom_vline(xintercept = 3, data = sample_data),
    "Ignoring `data`"
  )

  expect_warning(
    geom_hline(yintercept = 3, data = sample_data),
    "Ignoring `data`"
  )

  expect_warning(
    geom_abline(intercept = 3, data = sample_data),
    "Ignoring `data`"
  )

  expect_warning(
    geom_abline(intercept = 3, slope = 0.5, data = sample_data),
    "Ignoring `data`"
  )

  expect_warning(
    geom_abline(slope = 0.5, data = sample_data),
    "Ignoring `data`"
  )
})