hex_bin: Bin data into hexagons (2d).

Description Usage Arguments Value See Also Examples

Description

Bin data into hexagons (2d).

Usage

1
2
hex_bin(x, y, weight, width, height, xbins=20, ybins=20,
    na.rm=FALSE)

Arguments

x

a numeric vector of x positions

y

a numeric vector of y positions

weight

NULL or a numeric vector providing weights for each observation

height

height of each hexagon, if NULL computed from ybins

width

width of each hexagon, if NULL computed from ybins

xbins

number of horizontal bins, if width unspecified

ybins

number of vertical bins, if height unspecified

na.rm

If TRUE missing values will be silently removed, otherwise they will be removed with a warning.

Value

A data frame with columns x, y and freq, and attributes width and height.

See Also

hex_pos for algorithm that finds hexagon center closest to each point and hex_coord that generates coordinates of each hexagon.

Examples

1
2
3
4
5
plot(hex_bin(runif(1e4), runif(1e4)))
plot(hex_bin(rnorm(1e4), rnorm(1e4)))

data(baseball, package = "plyr")
bin <- hex_bin(baseball$g, baseball$ab)

hadley/densityvis documentation built on May 17, 2019, 9:56 a.m.