1 - GGplot - Stat - (Statistical transformation|Statistic)

2 - About

The Statistical transformation (stat). Multiple layers, statistical transformation.

It's often useful to transform your data before plotting, and that's what statistical transformations do.

Advertising

4 - Stat, geom relation

Every geom function has a default statistic:

And every statistic function has a default geom.

  • ''stat_…“

5 - List of statistic

Some statistics produce new data frame variables in the data. stat_bin produces count and density.

6 - Management

6.1 - Mapping a new stat to an aesthetic

Some statistics produce new data frame variables in the data.

Example: stat_bin produces count and density.

To map an aesthetic to one of the new stat variables, surround it with ..

p = ggplot(diamonds, aes(x=price))
p + geom_histogram(aes(y = ..density..))
p + geom_histogram(aes(colour = ..count..))
Advertising

6.2 - Separation of statistics and geometric elements

Ggplot - Geom (geometric objects) - type of plot

p <- ggplot(diamonds, aes(x=price))
p + stat_bin(geom="bar") # Equivalent to p + geom_histogram()
p + stat_bin(geom="area")
p + stat_bin(geom="point")
p + stat_bin(geom="line")
viz/ggplot/stat.txt · Last modified: 2017/12/11 11:41 by gerardnico