File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -547,7 +547,8 @@ Guides <- ggproto(
547547 direction = directions [i ], params = params [[i ]]
548548 )
549549 }
550- split(grobs , positions )
550+ keep <- ! vapply(grobs , is.zero , logical (1 ))
551+ split(grobs [keep ], positions [keep ])
551552 },
552553
553554 package_box = function (grobs , position , theme ) {
Original file line number Diff line number Diff line change @@ -477,6 +477,30 @@ test_that("guide_legend uses key.spacing correctly", {
477477 expect_doppelganger(" legend with widely spaced keys" , p )
478478})
479479
480+ test_that(" empty guides are dropped" , {
481+
482+ df <- data.frame (x = 1 : 2 )
483+ # Making a guide where all breaks are out-of-bounds
484+ p <- ggplot(df , aes(x , x , colour = x )) +
485+ geom_point() +
486+ scale_colour_continuous(
487+ limits = c(0.25 , 0.75 ),
488+ breaks = c(1 , 2 ),
489+ guide = " legend"
490+ )
491+ p <- ggplot_build(p )
492+
493+ # Empty guide that survives most steps
494+ gd <- get_guide_data(p , " colour" )
495+ expect_equal(nrow(gd ), 0 )
496+
497+ # Draw guides
498+ guides <- p $ plot $ guides $ draw(theme_gray(), direction = " vertical" )
499+
500+ # All guide-boxes should be empty
501+ expect_equal(lengths(guides , use.names = FALSE ), rep(0 , 5 ))
502+ })
503+
480504# Visual tests ------------------------------------------------------------
481505
482506test_that(" axis guides are drawn correctly" , {
You can’t perform that action at this time.
0 commit comments