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

label_* functions do not appear to work within aes() #487

Closed
py9mrg opened this issue Jan 19, 2025 · 2 comments
Closed

label_* functions do not appear to work within aes() #487

py9mrg opened this issue Jan 19, 2025 · 2 comments

Comments

@py9mrg
Copy link

py9mrg commented Jan 19, 2025

Hello,

I've just noticed that the new label_* versions do not seem compatible with being used inside aes(). Compare:

library(ggplot2)

ggplot(mtcars, aes(cyl, mpg)) +
  geom_point() +
  geom_text(aes(label = scales::comma(disp*1000)), vjust = 1, hjust = 1)

which works fine, with

library(ggplot2)
ggplot(mtcars, aes(cyl, mpg)) +
  geom_point() +
  geom_text(aes(label = scales::label_comma(disp*1000)), vjust = 1, hjust = 1)

Dont know how to automatically pick scale for object of type <function>. Defaulting to continuous.
Error in `geom_text()`:
! Problem while computing aesthetics.Error occurred in the 2nd layer.
Caused by error in `compute_aesthetics()`:
! Aesthetics are not valid data columns.The following aesthetics are invalid:`label = scales::label_comma(disp * 1000)`Did you mistype the name of a data column or forget to add `after_stat()`?
Run `rlang::last_trace()` to see where the error occurred.
@teunbrand
Copy link
Contributor

The function with the label_-prefix are function factories. If you want to use them as regular functions, you can use label_comma()(disp * 1000) for example. Though in this particular case, you could also use label_comma(scale = 1000)(disp).

@py9mrg
Copy link
Author

py9mrg commented Jan 19, 2025

@teunbrand ugh - of course I can. Total brainfreeze, sorry - thank you for your patience!

@py9mrg py9mrg closed this as completed Jan 19, 2025
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

No branches or pull requests

2 participants