stat_binstat_bin(mapping=NULL, data=NULL, geom="bar", position="stack", width=0.9, drop=FALSE, ...)
Bin data
Missing values are currently silently dropped.
This page describes stat_bin, see layer and qplot for how to create a complete plot from individual components.
What do you think of the documentation? Please let me know by filling out this short online survey.
The following aesthetics can be used with stat_bin. Aesthetics are mapped to variables in the data with the aes function: stat_bin(aes(x = var)). Note that you do not need quotes around the variable name.
Scales control how the variable is mapped to the aesthetic and are listed after each aesthetic.
| Aesthetic | Default | Related scales |
|---|---|---|
| x | required | continuous, date, datetime, discrete |
| y | ..count.. | continuous, date, datetime, discrete |
Layers are divided into groups by the group aesthetic. By default this is set to the interaction of all categorical variables present in the plot.
To use these variables in an aesthetic mapping, you need to surrond them with .., like aes(x = ..output..). This tells ggplot that the variable isn't the original dataset, but has been created by the statistic.
count, number of points in bindensity, density of points in bin, scaled to integrate to 1ncount, count, scaled to maximum of 1ndensity, density, scaled to maximum of 1Parameters control the appearance of the stat. In addition to the parameters listed below (if any), any aesthetic can be used as a parameter, in which case it will override any aesthetic mapping.
binwidth: Bin width to use. Defaults to 1/30 of the range of the data.origin: NULLbreaks: Actual breaks to use. Overrides bin widthwidth: Width of bars when used on categorical datadrop: NULL...: other argumentsThis function returns a layer object.
> m <- ggplot(movies, aes(x=rating)) > m + stat_bin() stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.> m + stat_bin(binwidth=0.1)
> m + stat_bin(breaks=seq(4,6, by=0.1))
> # See geom_histogram for more histogram examples > > # To create a unit area histogram, use aes(y = ..density..) > (linehist <- m + stat_bin(aes(y = ..density..), binwidth=0.1, + geom="line", position="identity"))
> linehist + stat_density(colour="blue", fill=NA)
> > # Also works with categorical variables > ggplot(movies, aes(x=mpaa)) + stat_bin()
> qplot(mpaa, data=movies, stat="bin")
![]()
What do you think of the documentation? Please let me know by filling out this short online survey.