1

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 and Position, Geom is a little different because the execution of the setup and compute functions is split up. setup_data runs before position adjustments, and draw_layer() is not run until render time, much later. This means there is no setup_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?

Zeke
  • 617
  • 1
  • 6
  • 15
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. It's hard to guess how exactly you might be using your geom at this point. – MrFlick Aug 03 '20 at 01:39

1 Answers1

2

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().

teunbrand
  • 33,645
  • 4
  • 37
  • 63