Skip to content

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

Closed

Description

@mikmart

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()

Activity

  1. yutannihilation commented on Nov 15, 2020

    @yutannihilation
    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))

  2. added
    bug
    on Mar 24, 2021
  3. added this to the ggplot2 3.3.4 milestone on Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglayers 📈

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions