Learn R Programming

ggplot2 (version 0.9.2.1)

stat_binhex: Bin 2d plane into hexagons.

Description

Bin 2d plane into hexagons.

Usage

stat_binhex(mapping = NULL, data = NULL, geom = "hex",
    position = "identity", bins = 30, na.rm = FALSE, ...)

Arguments

bins
numeric vector specifying number of bins in both x and y directions. Set to 30 by default.
na.rm
If FALSE (the default), removes missing values with a warning. If TRUE silently removes missing values.
mapping
The aesthetic mapping, usually constructed with aes or aes_string. Only needs to be set at the layer level if you are overriding the plot defaults.
data
A layer specific dataset - only needed if you want to override the plot defaults.
geom
The geometric object to use display the data
position
The position adjustment to use for overlappling points on this layer
...
other arguments passed on to layer. This can include aesthetics whose values you want to set, not map. See layer for more details.

Aesthetics

[results=rd,stage=build]{ggplot2:::rd_aesthetics("stat", "binhex")} d <- ggplot(diamonds, aes(carat, price)) d + stat_binhex() d + geom_hex()

# You can control the size of the bins by specifying the number of # bins in each direction: d + stat_binhex(bins = 10) d + stat_binhex(bins = 30)

# Or by specifying the width of the bins d + stat_binhex(binwidth = c(1, 1000)) d + stat_binhex(binwidth = c(.1, 500))

# With qplot qplot(x, y, data = diamonds, geom="hex", xlim = c(4, 10), ylim = c(4, 10)) qplot(x, y, data = diamonds, geom="hex", xlim = c(4, 10), ylim = c(4, 10), binwidth = c(0.1, 0.1))

stat_bin2d for rectangular binning