1
- context(" text " )
1
+ context(" Text " )
2
2
3
3
gg <- ggplot(mtcars , aes(x = wt , y = mpg , label = rownames(mtcars ))) +
4
4
geom_text(size = 18 )
@@ -18,3 +18,34 @@ 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
+
35
+ gg <- ggplot(mds ) +
36
+ geom_text(aes(x = coord.1 , y = coord.2 , label = City , colour = Division ))
37
+
38
+ L <- gg2list(gg )
39
+
40
+ expect_equal(length(L ), 3 ) # 2 traces + layout
41
+ # Proper type and mode conversion
42
+ expect_identical(L [[1 ]]$ type , " scatter" )
43
+ expect_identical(L [[1 ]]$ mode , " text" )
44
+ expect_identical(L [[2 ]]$ type , " scatter" )
45
+ expect_identical(L [[2 ]]$ mode , " text" )
46
+ # Right colour for each trace
47
+ expect_identical(L [[1 ]]$ textfont $ color , " #F8766D" )
48
+ expect_identical(L [[2 ]]$ textfont $ color , " #00BFC4" )
49
+
50
+ save_outputs(gg , " text-colour" )
51
+ })
0 commit comments