Adding statistics
In the previous chapter, you saw how plots are composed of different components and how the data, aesthetic mapping, and geometry are the three minimally required elements needed in order to make a plot. In reality, statistics are also needed in order to draw a plot, but it is not necessarily needed to be specified since, as we have seen in the previous chapter, each geometry has default statistics, which, in many cases, are simply the identity statistics. This stat
transformation actually does not produce anything on the data but leaves the data as it is in the plot. Another common stat that you have already used, probably without realizing it, is bin
, which is used by default, for instance, in histograms and barplots, to divide the data into bins that are then represented in the graph.
The default stat used from each geom
function will be sufficient in most common situations, but in some cases, it could be important for you to use a different stat or add an additional...