Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ggplot2 (development version)

* Make sure that default labels from default mappings doesn't overwrite default
labels from explicit mappings (@thomasp85, #2406)

* Fix a bug in `position_dodge2()` where `NA` values in thee data would cause an
error (@thomasp85, #2905)

Expand Down
12 changes: 10 additions & 2 deletions R/plot-construction.r
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,16 @@ ggplot_add.Layer <- function(object, plot, object_name) {

# Add any new labels
mapping <- make_labels(object$mapping)
default <- make_labels(object$stat$default_aes)
default <- lapply(make_labels(object$stat$default_aes), function(l) {
attr(l, "fallback") <- TRUE
l
})
new_labels <- defaults(mapping, default)
plot$labels <- defaults(plot$labels, new_labels)
current_labels <- plot$labels
current_fallbacks <- vapply(current_labels, function(l) isTRUE(attr(l, "fallback")), logical(1))
plot$labels <- defaults(current_labels[!current_fallbacks], new_labels)
if (any(current_fallbacks)) {
plot$labels <- defaults(plot$labels, current_labels)
}
plot
}