1
1
context(" Hline" )
2
-
3
2
# Horizontal line
4
3
5
- test_that(" Second trace be the hline" , {
6
-
7
- x1 <- seq(from = 0 , to = 3.5 , by = 0.5 )
8
- x2 <- x1 * 0.95
9
- df <- data.frame (" x1" = x1 , " x2" = x2 )
10
-
11
- gg <- ggplot(df ) + geom_point(aes(x = x1 , y = x2 )) +
12
- geom_hline(yintercept = 1.1 , colour = " green" , size = 3 )
4
+ x1 <- seq(from = 0 , to = 3.5 , by = 0.5 )
5
+ x2 <- x1 * 0.95
6
+ df <- data.frame (" x1" = x1 , " x2" = x2 )
7
+ gg <- ggplot(df ) + geom_point(aes(x = x1 , y = x2 ))
8
+
9
+ test_that(" second trace be the hline" , {
10
+ gg <- gg + geom_hline(yintercept = 1.1 , colour = " green" , size = 3 )
13
11
14
12
L <- gg2list(gg )
15
13
16
14
expect_equal(length(L ), 3 )
15
+ expect_equal(L [[2 ]]$ y [1 ], 1.1 )
17
16
expect_true(L [[2 ]]$ x [1 ] < = 0 )
18
17
expect_true(L [[2 ]]$ x [2 ] > = 3.5 )
19
18
expect_identical(L [[2 ]]$ mode , " lines" )
@@ -22,4 +21,23 @@ test_that("Second trace be the hline", {
22
21
expect_identical(L [[2 ]]$ line $ color , " rgb(0,255,0)" )
23
22
24
23
save_outputs(gg , " hline" )
25
- })
24
+ })
25
+
26
+ test_that(" vector yintercept results in multiple horizontal lines" , {
27
+ gg <- gg + geom_hline(yintercept = 1 : 3 , colour = " red" , size = 3 )
28
+
29
+ L <- gg2list(gg )
30
+
31
+ expect_equal(length(L ), 5 )
32
+ expect_equal(L [[2 ]]y [1 ], 1 )
33
+ expect_equal(L [[3 ]]y [1 ], 2 )
34
+ expect_equal(L [[4 ]]y [1 ], 3 )
35
+ expect_true(L [[4 ]]$ x [1 ] < = 0 )
36
+ expect_true(L [[4 ]]$ x [2 ] > = 3.325 )
37
+ expect_identical(L [[3 ]]$ mode , " lines" )
38
+ expect_identical(L [[3 ]]$ line $ shape , " linear" )
39
+ expect_equal(L [[3 ]]$ line $ width , 3 )
40
+ expect_identical(L [[3 ]]$ line $ color , " rgb(255,0,0)" )
41
+
42
+ save_outputs(gg , " hline-multiple" )
43
+ })
0 commit comments