Formal parameters in geoms and stats: how to pass them from one to the other?

geom_text, geom_label, and the repel equivalents have formal parameters that cannot be mapped to aesthetics. Several stats including the ones in my package 'ggspectra' also take parameters that cannot be mapped. My question is: can named arguments passed to a statistic through the ... parameter be forwarded to the geometry passed to the statistic as argument to its stat formal parameter (and vice versa)? and if it is possible, how is it done in 'ggplot2' (>=3.1.0)?

Thanks in advance for any hints on how to approach this problem!

Could you give an example (preferably with a reprex) to make this a bit more concrete?

Thanks!

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

For pointers specific to the community site, check out the reprex FAQ.

Thanks! Here is a rather contrived reprex that demonstrates the problem. (I had the impression that the ... would forward the additional named arguments, but this does not seem to be the case.)

library(ggplot2)
#> Registered S3 methods overwritten by 'ggplot2':
#>   method         from 
#>   [.quosures     rlang
#>   c.quosures     rlang
#>   print.quosures rlang

ggplot(mpg, aes(factor(cyl), hwy)) +
  stat_summary(fun.y = mean, geom = "col") +
  stat_summary(aes(label = round(stat(y))), 
               fun.y = mean, geom = "text", colour = "yellow",
               nudge_x = -0.2)
#> Warning: Ignoring unknown parameters: nudge_x


ggplot(mpg, aes(factor(cyl), hwy)) +
  geom_col(fun.y = mean, stat = "summary") +
  geom_text(aes(label = round(stat(y))), 
               fun.y = mean, stat = "summary", colour = "yellow",
               nudge_x = -0.2)
#> Warning: Ignoring unknown parameters: fun.y, stat

Created on 2019-05-13 by the reprex package (v0.2.1)

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