Constructs a reducer that can be used to show alternative summaries
in a plotscaper
plot.
Details
reducefn
and initialfn
should be strings interpretable
as JavaScript functions. Further:
initialfn
should take 0 arguments and just return some value (i.e. a thunk).reducefn
should take two argumentsprevious
andnext
and return a result of the same type asprevious
.
Examples
r <- reducer(initialfn = "() => 0",
reducefn = "(x, y) => Math.max(x, y)",
name = "max")
create_schema(mtcars) |>
add_barplot(c("cyl", "mpg"), options = list(reducer = r))
#> plotscaper schema:
#> add-plot { type: bar, variables: c("cyl", "mpg"), reducer: list(initialfn = "() => 0", reducefn = "(x, y) => Math.max(x, y)", name = "max") }