5.6 Statistical Transformations

Use a stat to calculate a new value. diamonds data gets “transformed” into a frequency table that get’s plotted by the bar plot.

Look at the geom_bar documentation, you will see the stat will be count (i.e., stat_count()).

You can set stat to ‘identity’ if you have already calculated a frequency table

grouping: http://ggplot2.tidyverse.org/reference/aes_group_order.html

By default, the group is set to the interaction of all discrete variables in the plot. This often partitions the data correctly, but when it does not, or when no discrete variable is used in the plot, you will need to explicitly define the grouping structure, by mapping group to a variable that has a different value for each group.