Statistical transformations

A stat is one of the five components of a layer

Statistical transformations, stats for short, transform the data, typically by summarising it in some manner. For example, a useful stat is the stat_smooth, which calculates the mean of y conditional on x, subject to some condition that ensures smoothness.

To make sense in a graphic context a stat must be location-scale. That is, f(x + a) = f(x) + a and f(b x) = b f(x). This ensures that the transformation is invariant under translation and scaling, common operations on a graphic.

A statistic takes a data frame as input and returns a data frame as output, and so a statistic can add new variables to the original data set. It is possible to map aesthetics to these new variables. For example, one way to describe a histogram is as a binning of a continuous variable, and then drawing bars with the number of points in each bin mapped to height and bin range mapped to x position. Another useful example is mapping the size of the lines in a contour plot to the level of the contour.