Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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)

* `stage()` now works correctly, even with aesthetics that do not have scales
(#5408)

* `geom_boxplot()` gains a new argument, `staplewidth` that can draw staples
at the ends of whiskers (@teunbrand, #5126)

Expand Down
2 changes: 1 addition & 1 deletion R/aes-evaluation.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ strip_stage <- function(expr) {
} else if (is_call(uq_expr, "stage")) {
# Prefer stat mapping if present, otherwise original mapping (fallback to
# scale mapping) but there should always be two arguments to stage()
uq_expr$after_stat %||% uq_expr$start %||% (if (is.null(uq_expr$after_scale)) uq_expr[[3]]) %||% uq_expr[[2]]
uq_expr$after_stat %||% uq_expr$start %||% uq_expr[[1]] %||% (if (is.null(uq_expr$after_scale)) uq_expr[[3]]) %||% uq_expr[[2]]
} else {
expr
}
Expand Down
6 changes: 3 additions & 3 deletions R/layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ Layer <- ggproto("Layer", NULL,
aesthetics[["group"]] <- self$aes_params$group
}

plot$scales$add_defaults(data, aesthetics, plot$plot_env)

# Evaluate aesthetics
env <- child_env(baseenv(), stage = stage)
evaled <- lapply(aesthetics, eval_tidy, data = data, env = env)
evaled <- compact(evaled)

plot$scales$add_defaults(evaled, plot$plot_env)

# Check for discouraged usage in mapping
warn_for_aes_extract_usage(aesthetics, data[setdiff(names(data), "PANEL")])

Expand Down Expand Up @@ -376,7 +376,7 @@ Layer <- ggproto("Layer", NULL,
stat_data <- data_frame0(!!!compact(stat_data))

# Add any new scales, if needed
plot$scales$add_defaults(data, new, plot$plot_env)
plot$scales$add_defaults(stat_data, plot$plot_env)
# Transform the values, if the scale say it's ok
# (see stat_spoke for one exception)
if (self$stat$retransform) {
Expand Down
16 changes: 4 additions & 12 deletions R/scales-.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,15 @@ ScalesList <- ggproto("ScalesList", NULL,

# `aesthetics` is a list of aesthetic-variable mappings. The name of each
# item is the aesthetic, and the value of each item is the variable in data.
add_defaults = function(self, data, aesthetics, env) {
if (is.null(aesthetics)) {
return()
}
names(aesthetics) <- unlist(lapply(names(aesthetics), aes_to_scale))

new_aesthetics <- setdiff(names(aesthetics), self$input())
add_defaults = function(self, data, env) {
new_aesthetics <- setdiff(names(data), self$input())
# No new aesthetics, so no new scales to add
if (is.null(new_aesthetics)) {
return()
}

data_cols <- lapply(aesthetics[new_aesthetics], eval_tidy, data = data)
data_cols <- compact(data_cols)

for (aes in names(data_cols)) {
self$add(find_scale(aes, data_cols[[aes]], env))
for (aes in new_aesthetics) {
self$add(find_scale(aes, data[[aes]], env))
}
},

Expand Down