@@ -11,4 +11,38 @@ test_that("segments become one path", {
11
11
tr <- info $ data [[1 ]]
12
12
expect_true(any(is.na(tr $ x )))
13
13
expect_true(any(is.na(tr $ y )))
14
+ save_outputs(gg , " segment" )
15
+ })
16
+
17
+ test_that(" with non-numeric data, we can have more than one segment" , {
18
+ df <- data.frame (donation = c(102.35377 , 98.80028 , 102.34715 , 103.71195 ,
19
+ 107.74814 , 92.21549 , 103.54709 , 93.52689 ,
20
+ 104.32014 , 93.23326 , 123.76597 , 128.53826 ,
21
+ 125.36151 , 116.29949 , 125.65676 , 118.60371 ,
22
+ 117.60477 , 128.28911 , 121.93446 , 127.63119 ,
23
+ 97.61806 , 94.25784 , 102.66568 , 100.75126 ,
24
+ 96.08688 , 89.15305 , 100.29993 , 89.76010 ,
25
+ 103.79008 , 96.71342 , 95.31541 , 107.68345 ,
26
+ 94.42277 , 98.91443 , 100.55720 , 104.00674 ,
27
+ 91.39054 , 94.11684 , 102.08854 , 97.04515 ),
28
+ campaign = c(1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
29
+ 2 , 2 , 2 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 ,
30
+ 2 , 2 , 2 , 2 , 2 , 2 ))
31
+
32
+ seg1 <- data.frame (x = 0.85 , xend = 1.15 , y = 100.2 , yend = 100.2 )
33
+ seg2 <- data.frame (x = 1.85 , xend = 2.15 , y = 123.5 , yend = 123.5 )
34
+
35
+ gg <- ggplot() +
36
+ geom_point(data = df , aes(x = campaign , y = donation , colour = campaign )) +
37
+ geom_segment(data = seg1 , aes(x , y , xend = xend , yend = yend )) +
38
+ geom_segment(data = seg2 , aes(x , y , xend = xend , yend = yend ))
39
+
40
+ fig <- gg2list(gg )
41
+ expect_equal(length(fig $ data ), 4 )
42
+ expect_equal(fig $ data [[3 ]]$ x [1 ], seg1 $ x )
43
+ expect_equal(fig $ data [[3 ]]$ x [2 ], seg1 $ xend )
44
+ expect_equal(fig $ data [[4 ]]$ x [1 ], seg2 $ x )
45
+ expect_equal(fig $ data [[4 ]]$ x [2 ], seg2 $ xend )
46
+
47
+ save_outputs(gg , " segment-multiple-non-numeric" )
14
48
})
0 commit comments