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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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

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
1 participant