20.3 Stats

Extending stats is one of the most useful ways to extend the capabilities of ggplot2

Stats are purely about data transformations

Creating new stats stat with these extension functions:

  • compute_*()
  • setup_*()

The logic of a stat is made of subsequent calls:

In general the transformation is done to single group starting at the compute_group() level.

Before compute_*() calls are thesetup_*() functions which allows the Stat to react and modify itself in response to the given parameters.

Sometimes, with related stats, all that is necessary is to make a subclass and provide new setup_params()/setup_data() methods.

print(stat_bin())
geom_bar: na.rm = FALSE, orientation = NA
stat_bin: binwidth = NULL, bins = NULL, center = NULL, boundary = NULL, breaks = NULL, closed = c("right", "left"), pad = FALSE, na.rm = FALSE, orientation = NA
position_stack