Skip to content

Commit

Permalink
Don't draw colorbar legend if empty. Fixes #967
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jun 15, 2015
1 parent 96b9cc4 commit a6e045e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
ggplot2 1.0.1.9000
----------------------------------------------------------------

* `guide_colorbar()` no longer fails when the legend is empty - previously
this often masked misspecifications elsewhere in the plot (#967)

* `Geom` is now exported, making it easier to create new geoms in other
packages (#989).

Expand Down
4 changes: 4 additions & 0 deletions R/guide-colorbar.r
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ guide_train.colorbar <- function(guide, scale) {
guide$key <- data.frame(scale_map(scale, breaks), I(scale_labels(scale, breaks)), breaks,
stringsAsFactors = FALSE)

if (nrow(guide$key) == 0) {
return()
}

# .value = breaks (numeric) is used for determining the position of ticks in gengrob
names(guide$key) <- c(output, ".label", ".value")

Expand Down

0 comments on commit a6e045e

Please sign in to comment.