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.
Every geom function has a default statistic:
And every statistic function has a default geom.
Statistic | Explanation |
---|---|
stat_bin | Statistics - (Discretizing|binning) (bin) |
stat_smooth | Statistic - Smooth (Function Continuity) (Soft ?) |
stat_density | Statistics - (Probability) Density Function (PDF) |
Some statistics produce new data frame variables in the data. stat_bin produces count and density.
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..))
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")