Skip to content

Commit ed2f8e8

Browse files
Fix after_scale() with plot mappings (#4265)
* Use plot$mapping in compute_geom_2() * Use default_mapping in guide_geom() * Merge mapping in setup_layer() * Stop merging a mapping repeatedly * Revert compute_geom_2() * Migrate a comment * Add a NEWS item
1 parent de0b9e3 commit ed2f8e8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
* Improved error with hint when piping a `ggplot` object into a facet function
3535
(#4379, @mitchelloharawild).
3636

37+
* Fix a bug that `after_stat()` and `after_scale()` cannot refer to aesthetics
38+
if it's specified in the plot-global mapping (@yutannihilation, #4260).
39+
3740
# ggplot2 3.3.3
3841
This is a small patch release mainly intended to address changes in R and CRAN.
3942
It further changes the licensing model of ggplot2 to an MIT license.

R/layer.r

+8-9
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,18 @@ Layer <- ggproto("Layer", NULL,
203203
# hook to allow a layer access to the final layer data
204204
# in input form and to global plot info
205205
setup_layer = function(self, data, plot) {
206+
# For annotation geoms, it is useful to be able to ignore the default aes
207+
if (isTRUE(self$inherit.aes)) {
208+
self$mapping <- defaults(self$mapping, plot$mapping)
209+
# defaults() strips class, but it needs to be preserved for now
210+
class(self$mapping) <- "uneval"
211+
}
212+
206213
data
207214
},
208215

209216
compute_aesthetics = function(self, data, plot) {
210-
# For annotation geoms, it is useful to be able to ignore the default aes
211-
if (self$inherit.aes) {
212-
aesthetics <- defaults(self$mapping, plot$mapping)
213-
} else {
214-
aesthetics <- self$mapping
215-
}
217+
aesthetics <- self$mapping
216218

217219
# Drop aesthetics that are set or calculated
218220
set <- names(aesthetics) %in% names(self$aes_params)
@@ -289,9 +291,6 @@ Layer <- ggproto("Layer", NULL,
289291

290292
# Assemble aesthetics from layer, plot and stat mappings
291293
aesthetics <- self$mapping
292-
if (self$inherit.aes) {
293-
aesthetics <- defaults(aesthetics, plot$mapping)
294-
}
295294
aesthetics <- defaults(aesthetics, self$stat$default_aes)
296295
aesthetics <- compact(aesthetics)
297296

0 commit comments

Comments
 (0)