tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.52k stars 2.03k forks source link

Allow position aesthetics other than x and y? #3898

Open paleolimbot opened 4 years ago

paleolimbot commented 4 years ago

This is an issue so that we remember to come back to this. As noted by. @clauswilke here: https://github.com/tidyverse/ggplot2/issues/3561#issuecomment-599091916 , constructing ternary diagrams using ggplot requires a lot of copying of ggplot2 code, which has resulted in the current breaking of the ggtern package.

At the heart of the issue is that a ternary diagram is a transformation of 3 variables, rather than 2. Currently, x- and y-scales are hard-coded in the Layout and other places, which makes adding an additional aesthetic that should be treated as a position aesthetic impossible (see https://github.com/tidyverse/ggplot2/issues/2540#issuecomment-570737499 ). I can't find the thread, but this came up in the context of coord_sf(), where geometry is also sort of a position aesthetic (that only sort of acts like one).

One approach would be to allow coords to define what is a position aesthetic. Currently there are a lot of definitions of "what is a position aesthetic" (#3342). If I remember correctly, this will break Coord and possibly Facet subclasses that are passed scale_x and scale_y.

Anyway, not pressing, just something that should be considered when coords are revisited.

teunbrand commented 4 years ago

To add another use case besides ternary diagrams, a z position aesthetic is also useful for plotting 3D structures projected onto 2D, similar to graphics::persp().

clauswilke commented 4 years ago

Discussion of geometry scales happened here: https://github.com/tidyverse/ggplot2/pull/3659#issuecomment-562962328

thomasp85 commented 4 years ago

I think this is a good discussion to take, but not of high priority. It would be nice to come up with a more extendible setup than what we currently have

davidchall commented 4 years ago

Similar to @teunbrand's use case of mapping 3D to 2D, I think there are also use cases that map 1D to 2D.

hughjonesd commented 1 year ago

This may not be exactly the same issue, but I have a ggplot extension which defines multiple x and y aesthetics (4 to be exact). I'd like to be able to tell scales "hey, this is an x aesthetic, please transform it according to your trans". So, basically, I want to be able to modify ggplot_global$x_aes, locally for my geom. Cf. #4135.

I can apply the transformation manually in Stat$compute_group(), but it's cumbersome and leads to ad hoc code. It also doesn't have access to aesthetics that were set, rather than scaled. Conversely, Stat$finish_data() has access to those aesthetics but not to the scale.