why isn't the data the first argument passed to a geom_*()

Hi fellow R users,

I ran into a funny error that made me realize the order in which we pass argument on to a geom_*()

this is from the posit documentation

geom_smooth(
  mapping = NULL,
  data = NULL,
  stat = "smooth",
  position = "identity",

The question is WHY isn't data the first argument passed on to the geom_*() like you do in every other tidyverse function?

Thanks for any insights you can send my waya

Because the package was developed before the rest of tidyverse including magrittr which makes that most attractive to have in a function.

3 Likes

My answer would be that in the bulk of uses of ggplot(), only a single data source is necessary, whereas the mappings often change in every layer. Also, layer functions in ggplot() are not like other tidyverse functions in that they do not return an object that is available to be further processed so much as an object that is to be added to the current plot.

1 Like

This topic was automatically closed 90 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.