xy2hcell {hexDensity} | R Documentation |
Find the hexagon cells from xy coordinates given a hexbin object.
Description
Find the hexagon cells IDs from xy coordinates given a hexbin object. Useful if you want to get the KDE value at a certain coordinate.
Usage
xy2hcell(
hexbin = NULL,
x,
y = NULL,
xbins = NULL,
xbnds = NULL,
ybnds = NULL,
shape = NULL
)
Arguments
hexbin |
hexbin object to be referenced to. |
x , y |
coordinates or vectors of coordinates of the points. |
xbins |
number of bins partitioning the range of xbnds |
xbnds , ybnds |
horizontal and vertical limit of the binning region. Must be numeric vector of length 2. |
shape |
shape = yheight/xwidth of the plotting regions. |
Details
If a hexbin object is not provided, parameters of the binning region (xbins, xbnds, ybnds, shape) can be used instead. For finding the xy coordinates of the hexagons for a hexbin object, see hcell2xy.
Value
a vector the same length as x with the hexagonal cell ID for each point
Examples
library(hexbin)
set.seed(133)
d=hexDensity(x=rnorm(20000),y=rnorm(20000),xbins=50)
#Get KDE value at the coordinate x=0,y=0
loc = xy2hcell(d,x=0,y=0)
d@count[loc]
[Package hexDensity version 1.4.8 Index]