stat_bin2dstat_bin2d(mapping=NULL, data=NULL, geom="rect", position="identity", bins=30, drop=TRUE, ...)
Bin 2d plane into rectangles
This page describes stat_bin2d, 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_bin2d. Aesthetics are mapped to variables in the data with the aes function: stat_bin2d(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 | required | continuous, date, datetime, discrete |
| fill | ..count.. | brewer, gradient, gradient2, gradientn, grey, hue, identity, manual |
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.
Parameters 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: NULLbins: NULLbreaks: numeric vector indicating where breaks should lieorigin: NULLdrop: NULL...: ignored This function returns a layer object.
> d <- ggplot(diamonds, aes(carat, price)) > d + stat_bin2d()> d + geom_bin2d()
> > # You can control the size of the bins by specifying the number of > # bins in each direction: > d + stat_bin2d(bins = 10)
> d + stat_bin2d(bins = 30)
> > # Or by specifying the width of the bins > d + stat_bin2d(binwidth = c(1, 1000))
> d + stat_bin2d(binwidth = c(.1, 500))
> > # Or with a list of breaks > x <- seq(min(diamonds$carat), max(diamonds$carat), by = 0.1) > y <- seq(min(diamonds$price), max(diamonds$price), length = 50) > d + stat_bin2d(breaks = list(x = x, y = y))
> > # With qplot > qplot(x, y, data = diamonds, geom="bin2d", + xlim = c(4, 10), ylim = c(4, 10))
> qplot(x, y, data = diamonds, geom="bin2d", binwidth = c(0.1, 0.1), + xlim = c(4, 10), ylim = c(4, 10))
![]()
What do you think of the documentation? Please let me know by filling out this short online survey.