diff --git a/NEWS b/NEWS index b1c0d2f183..09c0f77f6f 100644 --- a/NEWS +++ b/NEWS @@ -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). diff --git a/R/guide-colorbar.r b/R/guide-colorbar.r index 8a895a78ca..747fac9e5e 100644 --- a/R/guide-colorbar.r +++ b/R/guide-colorbar.r @@ -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")