Shared computation between plot layers
I can imagine that two stats both have a full compute but store the intermediate results (e.g. the model in geom_smooth()) in a cache. The cache can then be read out by the second stat, which then doesn't have to do the full compute step. You can then use the Stat$finish_layer, which is executed after all stat computation have completed, to clear the cache for the next round of computation.
Originally posted by @teunbrand in https://github.com/ggplot2-extenders/ggplot-extension-club/discussions/117#discussioncomment-14390503
A cache is something I have considered, but have not got around to implement in 'ggpmisc'. Two UI are possible: checking that the new layer call has the same arguments as the cached one, or a lot simpler, let the user explicitly request to reuse the cached computation results. Even the request to cache the results from the first layer could be explicit. The most intuitive approach would be to extend the grammar using an operator to indicate the layers that share computations. The code could then look something like:
ggplot(data, aes()) +
geom_point() +
stat_poly_line(formula, method) > stat_poly_eq()
|> could possibly be used instead of >, similarly as it is used in 'ggplender'. But in 'ggblender' |> works across multiple layers, not just a pair of layers.