stat_binhex

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

Bin 2d plane into hexagons

This page describes stat_binhex, 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.

Aesthetics

The following aesthetics can be used with stat_binhex. Aesthetics are mapped to variables in the data with the aes function: stat_binhex(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
xrequiredcontinuous, date, datetime, discrete
yrequiredcontinuous, 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

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.

Returns

This function returns a layer object.

See also

Examples

> 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)) 
Warning: Removed 478 rows containing missing values (stat_hexbin).
  
> qplot(x, y, data = diamonds, geom="hex", xlim = c(4, 10), ylim = c(4, 10), 
+   binwidth = c(0.1, 0.1)) 
Warning: Removed 478 rows containing missing values (stat_hexbin).
  

What do you think of the documentation? Please let me know by filling out this short online survey.