-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Feature requests: Composable mappings #4789
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
Comments
Alternative api that behaves more like classic vectors: col_aes <- aes(col = gear)
ggplot(mtcars) + geom_point(aes(x = mpg, y = disp, col_aes)) |
That also seems like a nice way to combine them. Might also be able to do |
We can already do |
I was unaware of this possibility, and it does seem convenient, so thank you for pointing this out. Having a quick play with this, it seems it works when the named library(ggplot2)
col_aes <- aes(colour = gear)
aes(!!!col_aes)
#> Error in `FUN()`:
#> ! Can't use `!!!` at top level.
aes(x = mpg, !!!col_aes)
#> Error in `FUN()`:
#> ! Can't use `!!!` at top level.
aes(x = mpg, y = disp, !!!col_aes)
#> Aesthetic mapping:
#> * `x` -> `mpg`
#> * `y` -> `disp`
#> * `colour` -> `gear` If you provide x_aes <- aes(x = mpg)
aes(y = disp, !!!x_aes)
#> Error in `FUN()`:
#> ! Can't use `!!!` at top level. Created on 2022-04-01 by the reprex package (v2.0.1) |
Ah, true. Sorry, I forgot the problem. I think there is some open issue related to this behaviour, but I couldn't find it. |
I think I may have found it in #2675. I suppose if that issue can be solved, this feature request is redundant, so feel free to close this in favour of the other issue. |
Thanks, yes, that one. I hope so, but, considering I've failed to solve #2675, maybe we need some fresh approach. Let's keep this issue open. |
Yeah, you only need to get past the first two arguments for it to work: library(ggplot2)
col_aes <- aes(colour = gear)
aes(,,!!!col_aes)
#> Aesthetic mapping:
#> * `colour` -> `gear` Created on 2022-04-14 by the reprex package (v2.0.1) I'd rather support |
Hi ggplot2 team,
In brief: I think it would be neat if it was possible to do
aes(x = 1, y = 2) + aes(colour = class)
, and get the equivalent ofaes(x = 1, y = 2, colour = class)
. In effect, I'm suggesting that theaes()
mappings might be composed, much like the layers of a plot.Why might this be neat? I'm probably not the only one who writes out small novels in most
aes()
calls. Most of them are pretty repetitive among layers or plots, but not exactly repetitive enough to warrant assigning the mapping to a variable for reuse.Consider the example below, wherein we might want to recycle the
colour
mapping to other plots/layers as well. For instance, another dataset with different column names, which renders thefill
part invalid, or another layer with similar but not duplicated mappings.What I'm suggesting is to write some mechanism wherein parts of mappings can be easily combined. For example:
This then allows you to set the
colour
outside of the plot, combine it with the mapping of the layer, and reuse it elsewhere at a later point.Created on 2022-03-31 by the reprex package (v2.0.1)
Thank you for your work and consideration of this FR!
The text was updated successfully, but these errors were encountered: