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

Using after_scale() in Geom$default_aes field #6137

Merged
merged 6 commits into from
Oct 30, 2024

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6135.

It works by appending any scaled/staged expressions in Geom$default_aes to the modified computed mapping and evaluating these along with them.

Reprex from issue:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

GeomPointAlt <- ggproto(
  "GeomPointAlt", GeomPoint,
  default_aes = aes(
    colour = after_scale(alpha(fill, 0.4)),
    fill = "black",
    # Merge with default, removing pre-existing `colour`/`fill`
    !!!utils::modifyList(GeomPoint$default_aes, list(colour = NULL, fill = NULL))
  )
)

The issue exposed in #6135 (comment), note that colour now has an alpha channel.

get_geom_defaults(GeomPointAlt)
#>      colour shape size alpha stroke  fill
#> 1 #00000066    19  1.5    NA    0.5 black

Display is identical to desired plot in issue:

ggplot(mpg, aes(displ, hwy, fill = drv)) +
  stat_identity(geom = GeomPointAlt)

Created on 2024-10-15 with reprex v2.1.1

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit 579e2d5 into tidyverse:main Oct 30, 2024
13 checks passed
@teunbrand teunbrand deleted the delayed_geom_defaults branch October 30, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

after_scale() does not work in Geom$default_aes field
2 participants