Skip to content

Layers inheriting aesthetics at the stage or whole aesthetic level #4491

@mdlama

Description

@mdlama

Hi, everyone. I don't think there is an answer per se to this question, but I ran across an issue when I wanted to create the following side-by-side jitter and boxplot:

library(ggplot2)
ggplot(iris, 
       aes(x = Species, y = Sepal.Length)) + 
  geom_jitter(aes(x = stage(start = Species, after_scale = x - 0.1)), 
              width = 0.05) + 
  geom_boxplot(width = 0.1, 
               position = position_nudge(x = 0.1), 
               outlier.alpha = 0)

d874462b099af08a086c219bc3d07ccf5dd3e4a7

Created on 2021-05-24 by the reprex package (v0.3.0.9001)

Basically, I wanted the plots to be centered on the tick marks, which required a nudge in opposite directions for each. The boxplot was easiest with the use of position_nudge. The stripchart was a little more difficult, given the fact that there is no built-in position_jitternudge. The fairly recent addition of our ability to manipulate the aesthetic mapping stages makes this possible, however, by specifying a manual nudge in the after_scale step. Notice, however, that I have to repeat the start aesthetic mapping, even though aesthetic inheriting is on for the geom_point layer (by default). To illustrate that I need to specify it, here's a reprex of just specifying the after_scale part (this was my initial try at the plot, where I incorrectly assumed the start stage would be inherited):

library(ggplot2)
ggplot(iris, 
       aes(x = Species, y = Sepal.Length)) + 
  geom_jitter(aes(x = after_scale(x - 0.1)), 
              width = 0.05) + 
  geom_boxplot(width = 0.1, 
               position = position_nudge(x = 0.1), 
               outlier.alpha = 0)
#> Error: geom_point requires the following missing aesthetics: x

Created on 2021-05-24 by the reprex package (v0.3.0.9001)

In summary: it appears that aesthetic inheritance, and overriding them, happens at the whole mapping level, rather than at the individual stage level. So here's my question: Would it make sense to allow for overriding inherited aesthetics at the individual stage levels to avoid duplicate mapping specifications?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions