Closed aphalo closed 1 year ago
The list of functions would then be mapped to the y
or x
aesthetics, and orientation
would be set automatically, based on this or overriden through parameter orientation
.
Now I know how this stat should work! Aesthetic mappings without redundancy can be achieved. Map list of functions to y
, and map range to xmin
and xmax
or, possibly, functions to x
and range to ymin
and ymax
. This gives one function for each row in data
making it easy to use, but making it possible to fully support the grammar of graphics.
Initial version mplemented and working. No unit tests yet, but examples do work as expected. Parameter orientation
is not yet implemented.
stat_function()
from 'ggplot2' works like an annotation, and accepts a single function. This does not match the expectations of the grammar of graphics. In the newstat_functions()
the functions would be in a list column indata
, the code in the stat would compute y values for each function from x values if available indata
. Unlikestat_function()
,x
values would not be generated automatically, but possibly sparse vectors giving a range could be populated by interpolation (opposite tostat_summary()
the returneddata
object would have more rows than the inputdata
object).If 'ggplot2' code can do the aesthetic mapping as it does for whole data frames and gg objects for insets, this would be fairly easy to implement.
An alternative would be to prepare a pull request to 'ggplot2' revising
stat_function()
to accept vectors or lists asgeom_hline()
and similar functions do.The idea was triggered by the necessarily complex and inelegant code included in a question at StackOverflow as example, not by the question itself.