Skip to content

annotate() gives warning when passing position or stat #5746

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

Merged
merged 3 commits into from
Mar 18, 2024

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5151.

Briefly, annotate() is hardcoded to use StatIdentity and PositionIdentity so any stat or position argument to annotate() ends up in the params to the layer. This PR warns about such cases and pre-emptively removes these arguments.

Demo:

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

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  annotate(
    "point", x = 3, y = 40,
    position = position_jitter()
  )
#> Warning: `annotate()` can't accept `position` argument.

Created on 2024-03-05 with reprex v2.1.0

@teunbrand teunbrand added this to the ggplot2 3.5.1 milestone Mar 5, 2024
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 87a76e8 into tidyverse:main Mar 18, 2024
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.

position argument is not passed to layer() in annotate()
2 participants