Skip to content

Commit

Permalink
Fix weird legend bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Dec 9, 2009
1 parent aebe355 commit b25b52b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -36,3 +36,4 @@ ggplot2 0.8.5 (2009-XX-XX) ----------------------------------------
have formatter argument to match scale_continuous
* legends will only merge if both the title and all labels are the same.
(Fixes #16)
* Fix for bug #19: Legend with three constraints doesn't work
3 changes: 1 addition & 2 deletions R/guides-legend.r
Expand Up @@ -75,7 +75,6 @@ guide_legends <- function(scales, layers, default_mapping, theme) {
} else {
keys <- keys[[1]]
}

build_legend(title, keys, layers, default_mapping, theme)
})
}
Expand Down Expand Up @@ -166,7 +165,7 @@ build_legend <- function(name, mapping, layers, default_mapping, theme) {
build_legend_data <- function(layer, mapping, default_mapping) {
all <- names(c(layer$mapping, default_mapping, layer$stat$default_aes()))
geom <- c(layer$geom$required_aes, names(layer$geom$default_aes()))

matched <- intersect(intersect(all, geom), names(mapping))
matched <- setdiff(matched, names(layer$geom_params))

Expand Down
4 changes: 3 additions & 1 deletion R/layer.r
Expand Up @@ -84,10 +84,12 @@ Layer <- proto(expr = {
clone <- function(.) as.proto(.$as.list(all.names=TRUE))

use_defaults <- function(., data) {
df <- aesdefaults(data, .$geom$default_aes(), compact(.$mapping))
mapped_vars <- .$mapping[!sapply(.$mapping, is.character)]
df <- aesdefaults(data, .$geom$default_aes(), mapped_vars)

# Override mappings with parameters
gp <- intersect(c(names(df), .$geom$required_aes), names(.$geom_params))

if (length(.$geom_params[gp]))
gp <- gp[sapply(.$geom_params[gp], is.atomic)]
df[gp] <- .$geom_params[gp]
Expand Down

0 comments on commit b25b52b

Please sign in to comment.