@@ -18,3 +18,30 @@ test_that("textsize is translated correctly", {
18
18
})
19
19
20
20
save_outputs(gg , " text" )
21
+
22
+ test_that(" geom_text splits along colour" , {
23
+ mds <- data.frame (State = c(" Alabama" , " Alabama" , " Alabama" , " Alabama" ,
24
+ " Arizona" , " Arizona" ),
25
+ City = c(" HUNTSVILLE" , " MOBILE" , " BIRMINGHAM" , " MONTGOMERY" ,
26
+ " TUCSON" , " PEORIA" ),
27
+ coord.1 = c(1.561284 , 6.088862 , 9.978292 , 15.454877 ,
28
+ 23.225289 , - 7.283954 ),
29
+ coord.2 = c(0.2228790 , 0.8343259 , - 3.6507234 , - 4.8520206 ,
30
+ - 0.4438650 , 9.1252792 ),
31
+ Division = c(" East South Central" , " East South Central" ,
32
+ " East South Central" , " East South Central" ,
33
+ " Mountain" , " Mountain" ))
34
+ gg <- ggplot(mds ) +
35
+ geom_text(aes(x = coord.1 , y = coord.2 , label = City , colour = Division ))
36
+ L <- gg2list(gg )
37
+ expect_equal(length(L ), 3 ) # 2 traces + layout
38
+ # Proper type and mode conversion
39
+ expect_identical(L [[1 ]]$ type , " scatter" )
40
+ expect_identical(L [[1 ]]$ mode , " text" )
41
+ expect_identical(L [[2 ]]$ type , " scatter" )
42
+ expect_identical(L [[2 ]]$ mode , " text" )
43
+ # Right colour for each trace
44
+ expect_identical(L [[1 ]]$ textfont $ color , " #F8766D" )
45
+ expect_identical(L [[2 ]]$ textfont $ color , " #00BFC4" )
46
+ save_outputs(gg , " text-colour" )
47
+ })
0 commit comments