@@ -36,13 +36,37 @@ test_that("geom_smooth() respects group aesthetic", {
36
36
})
37
37
38
38
p4 <- qplot(carat , price , colour = cut , data = d ) + geom_smooth()
39
+ p5 <- qplot(carat , price , data = d ) + geom_smooth(aes(colour = cut ))
39
40
40
41
test_that(" geom_smooth() respects colour aesthetic" , {
41
42
info <- expect_traces(p4 , 11 , " colour" )
43
+ # number of showlegends should equal the number of factor levels
44
+ n <- sum(unlist(sapply(info $ traces , " [[" , " showlegend" )))
45
+ expect_equal(n , nlevels(d $ cut ))
46
+ info <- expect_traces(p5 , 11 , " colour2" )
47
+ n <- sum(unlist(sapply(info $ traces , " [[" , " showlegend" )))
48
+ expect_equal(n , nlevels(d $ cut ))
42
49
})
43
50
44
- p5 <- qplot(carat , price , fill = cut , data = d ) + geom_smooth()
51
+ # why are 5 traces for point being created here??
52
+ # p6 <- qplot(carat, price, fill = cut, data = d) + geom_smooth()
53
+ p7 <- qplot(carat , price , data = d ) + geom_smooth(aes(fill = cut ))
45
54
46
55
test_that(" geom_smooth() respects fill aesthetic" , {
47
- info <- expect_traces(p5 , 11 , " fill" )
56
+ # info <- expect_traces(p6, 11, "fill")
57
+ # n <- sum(unlist(sapply(info$traces, "[[", "showlegend")))
58
+ # expect_equal(n, nlevels(d$cut))
59
+ info <- expect_traces(p7 , 11 , " fill2" )
60
+ n <- sum(unlist(sapply(info $ traces , " [[" , " showlegend" )))
61
+ expect_equal(n , nlevels(d $ cut ))
48
62
})
63
+
64
+ # ensure legend is drawn when needed
65
+ p8 <- qplot(carat , price , data = d ) + facet_wrap(~ cut ) +
66
+ geom_smooth(aes(colour = cut , fill = cut ))
67
+
68
+ test_that(" geom_smooth() works with facets" , {
69
+ # 3 traces for each panel
70
+ info <- expect_traces(p8 , 15 , " fill2" )
71
+ })
72
+
0 commit comments