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

position argument is not passed to layer() in annotate() #5151

Closed
dmi3kno opened this issue Jan 15, 2023 · 3 comments · Fixed by #5746
Closed

position argument is not passed to layer() in annotate() #5151

dmi3kno opened this issue Jan 15, 2023 · 3 comments · Fixed by #5746

Comments

@dmi3kno
Copy link

dmi3kno commented Jan 15, 2023

The argument position is not passed through ellipsis to the layer() command from annotate()

ggplot(mtcars,aes(disp,mpg))+geom_point()+
annotate("text", x=min(mtcars$disp), y=max(mtcars$mpg), label="Value", hjust=0, position=position_nudge(x=10))
#> Warning message:
#> In annotate("text", x = min(mtcars$disp), y = max(mtcars$mpg), label = "Value",  :
#>  Ignoring unknown parameters: `position`
@smouksassi
Copy link

you can just use geom_text

library(ggplot2)

ggplot(mtcars,aes(disp,mpg))+
  geom_point()+
  annotate("text",
           x=-Inf,
           y=Inf,
           label="Value",
           hjust=0,
           vjust=1.5)

ggplot(mtcars,aes(disp,mpg))+
  geom_point()+
  geom_text(data=data.frame( x=min(mtcars$disp),
                             y=max(mtcars$mpg),
                             label="Value"),
            aes(x=x,y=y,label=label),
            hjust=0, position=position_nudge(x=10))

Created on 2023-01-16 with reprex v2.0.2

@dmi3kno
Copy link
Author

dmi3kno commented Jan 16, 2023

I am aware, thank you. Something goes irrecoverably bad in PDF when I use plotmath in the label for geom_text(). This is not happening in annotate(). I would like annotate() to work as advertised.

@teunbrand
Copy link
Collaborator

It also doesn't pass any stat to layer() either. The position and stat of the layer are hardcoded to be the identity position/stat. I think there are three options:

  • Improve documentation of the ... to explicitly state what can and cannot be passed to layer this way (WIP).
  • Throw an error when stat or position are passed to annotate().
  • Allow position and stat in annotate(). I tried searching the history of annotate() for a reason why positions and stats aren't allowed, but came up empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants