@@ -51,22 +51,21 @@ test_that("Colorbar respects show.legend in layer", {
51
51
df <- data_frame(x = 1 : 3 , y = 1 )
52
52
p <- ggplot(df , aes(x = x , y = y , color = x )) +
53
53
geom_point(size = 20 , shape = 21 , show.legend = FALSE )
54
- expect_false(" guide-box" %in% ggplotGrob(p )$ layout $ name )
54
+ expect_false(any(grepl( " guide-box" , ggplotGrob(p )$ layout $ name )) )
55
55
p <- ggplot(df , aes(x = x , y = y , color = x )) +
56
56
geom_point(size = 20 , shape = 21 , show.legend = TRUE )
57
- expect_true(" guide-box" %in% ggplotGrob(p )$ layout $ name )
57
+ expect_true(any(grepl( " guide-box" , ggplotGrob(p )$ layout $ name )) )
58
58
})
59
59
60
60
test_that(" show.legend handles named vectors" , {
61
61
n_legends <- function (p ) {
62
62
g <- ggplotGrob(p )
63
- gb <- which(g $ layout $ name == " guide-box" )
64
- if (length(gb ) > 0 ) {
65
- n <- length(g $ grobs [[gb ]]) - 1
66
- } else {
67
- n <- 0
68
- }
69
- n
63
+ gb <- grep(" guide-box" , g $ layout $ name )
64
+ n <- vapply(g $ grobs [gb ], function (x ) {
65
+ if (is.zero(x )) return (0 )
66
+ length(x $ grobs ) - 1
67
+ }, numeric (1 ))
68
+ sum(n )
70
69
}
71
70
72
71
df <- data_frame(x = 1 : 3 , y = 20 : 22 )
0 commit comments