Skip to content

aesthetics error if only argument is an expression #2764

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

Closed
emrichter opened this issue Jul 18, 2018 · 5 comments
Closed

aesthetics error if only argument is an expression #2764

emrichter opened this issue Jul 18, 2018 · 5 comments

Comments

@emrichter
Copy link

I'm trying to dynamically generate a ggplot-object from within a function. For this, I save a parameter name like "color" or "fill" (dependent on the geom) as an expression and I unquote it within aes().
As long as I leave the x and y in the geom-function everything works. If I move them to ggplot() though, I get an error.
What am I missing?

Here a repex:

library(ggplot2)
library(rlang)

arg <- expr(color)

#working
ggplot(data = mpg) +
  geom_point(aes(displ, cty, !!arg := manufacturer))

#not working
ggplot(data = mpg, aes(displ, cty)) +
  geom_point(aes(!!arg := manufacturer))
@clauswilke
Copy link
Member

I believe this is the same issue as #2675.

@emrichter
Copy link
Author

Thanks a lot. So I'll wait till it's solved : )

@batpigandme
Copy link
Contributor

@emrichter yes. I'll close this, since it's the same issue, though.

@hadley
Copy link
Member

hadley commented Jul 22, 2018

BTW there's an easy work around in the mean time:

ggplot(data = mpg, aes(displ, cty)) +
  geom_point(aes(,, !!arg := manufacturer))

@lock
Copy link

lock bot commented Jan 18, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants