bin_2d_fixed: Bin in 2d

Description Usage Arguments Examples

View source: R/bin-2d.R

Description

Each argument can either be NULL, a vector of length 1 (which will be used for both x and y directions), or a vector of length 2.

Usage

1
2
3
bin_2d_fixed(x, y, width = NULL, center = NULL, boundary = NULL,
  origin = NULL, terminus = NULL, bins = 30, pad = FALSE,
  closed = NULL)

Arguments

x, y

Numeric vectors to guess parameters from.

width

(Positive real). The width of a bin. For S3 objects, the interpretation of width depends on the interpretation of the underlying numeric vector. For example, for dates, 1 = 1 day; for times 1 = 1 second; and for difftime, the units vary.

If NULL, the width will be derived from the data, picking approximately bins bins with nice widths. You should always override this value, exploring multiple widths to find the best to illustrate the stories in your data.

center

Set the position of the first bin by specifying the position of either a boundary or the center of a bin. For example, you can always center the bins on integers with center = 0 regardless of where the first bin actually falls.

Think of binning as tiling the real line into a infinite sequence of intervals. center and boundary set the position of one of those intervals.

boundary

Set the position of the first bin by specifying the position of either a boundary or the center of a bin. For example, you can always center the bins on integers with center = 0 regardless of where the first bin actually falls.

Think of binning as tiling the real line into a infinite sequence of intervals. center and boundary set the position of one of those intervals.

origin

The locations of the left-most and right-most bins. Any values outside this range will be treated as missing. You should usually leave origin as NULL so that it is automatically computed from center and boundary.

terminus

The locations of the left-most and right-most bins. Any values outside this range will be treated as missing. You should usually leave origin as NULL so that it is automatically computed from center and boundary.

bins

Number of bins to use if not specified. Pretty bin sizes are preferred over matching this value exactly.

pad

If TRUE, adds empty bins at either end of x. This ensures frequency polygons touch 0 outside the range of x. Defaults to FALSE.

closed

One of "right" or "left" indicating whether the bin interval is left-closed (i.e. [a, b)), or right-closed (i.e. (a, b]).

Examples

1
2
3
4
5
6
7
8
bin_2d_fixed(runif(100), runif(100))
bin_2d_fixed(runif(100), runif(100), origin = 0)
bin_2d_fixed(runif(100), runif(100), width = 0.25)
bin_2d_fixed(runif(100), runif(100), bins = c(10, 100))

mat <- MASS::mvrnorm(1e6, mu = c(0, 0), matrix(c(1,0.5,0.5,1),2,2))
bins <- bin_2d_fixed(c(-3, 3), c(-3, 3))
system.time(out <- compute_stat(bins, mat[, 1], mat[, 2]))

hadley/ggstat documentation built on May 17, 2019, 10:40 a.m.