Layers inheriting aesthetics at the stage or whole aesthetic level

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)

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 stage level to avoid duplicate mapping specifications?

This is an interesting design question, and you might want to ask it as an issue in the ggplot2 repo, if there hasn't already been a related discussion. :slightly_smiling_face:

Thanks, Mara. I will indeed ask as an issue in the ggplot2 repo, and link to it here when it is up in case someone stumbles upon this in the future.

Edit:...and the issue on GitHub for the curious

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.