Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after_scale() in the initial ggplot() call #4260

Closed
mikmart opened this issue Nov 7, 2020 · 1 comment · Fixed by #4265
Closed

after_scale() in the initial ggplot() call #4260

mikmart opened this issue Nov 7, 2020 · 1 comment · Fixed by #4265
Labels
bug an unexpected problem or unintended behavior layers 📈
Milestone

Comments

@mikmart
Copy link
Contributor

mikmart commented Nov 7, 2020

Consider the after_scale() example from ?aes_eval:

library(ggplot2) # tidyverse/ggplot2@a132727

ggplot(mpg, aes(class, hwy)) +
  geom_boxplot(aes(colour = class, fill = after_scale(alpha(colour, 0.4))))

Moving the colour and fill specification form the geom to the initial ggplot() call causes the fill to not be mapped at all:

ggplot(mpg, aes(class, hwy, colour = class, fill = after_scale(alpha(colour, 0.4)))) +
  geom_boxplot()

@yutannihilation
Copy link
Member

Thanks, this seems because Layer$compute_geom_2() refers only to the layer's mapping and ignores plot$mapping.

ggplot2/R/layer.r

Lines 356 to 364 in a132727

compute_geom_2 = function(self, data) {
# Combine aesthetics, defaults, & params
if (empty(data)) return(data)
aesthetics <- self$mapping
modifiers <- aesthetics[is_scaled_aes(aesthetics) | is_staged_aes(aesthetics)]
self$geom$use_defaults(data, self$aes_params, modifiers)
},

I think compute_geom_2() needs to take plot as we do with map_statistics().

data <- by_layer(function(l, d) l$map_statistic(d, plot))

@thomasp85 thomasp85 added bug an unexpected problem or unintended behavior layers 📈 labels Mar 24, 2021
@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior layers 📈
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants