Reputation: 669
I'm working on making my own geom for ggplot2, and I've noticed that in ggplot2's documentation, it explicitly says that there is no setup_params()
for geoms:
Compared to
Stat
andPosition
,Geom
is a little different because the execution of the setup and compute functions is split up.setup_data
runs before position adjustments, anddraw_layer()
is not run until render time, much later. This means there is nosetup_params
because it's hard to communicate the changes.
However, when I make a ggproto Geom that has setup_params = function(data, params) {...}
, it calls that function fine, and it seemingly works.
What gives? Can I use this function to modify parameters or not?
Upvotes: 1
Views: 394
Reputation: 37913
Yes you can use it just fine, the methods were added in ggplot2 3.3.0 and it's use was advertised in their NEWS.md file. It was added in https://github.com/tidyverse/ggplot2/pull/3509 in an effort to improve consistency in ggproto classes.
Like you I find the documentation on this a bit confusing, but it was probably overlooked when adding the new setup_params()
. It would probably make sense to open an issue at the ggplot2 github to document this new(er) use of setup_params()
.
Upvotes: 2