sqbin: Square binning of xy data

View source: R/sqbin.R

sqbinR Documentation

Square binning of xy data

Description

The sqbin function calculates frequencies in xy bins

Usage

sqbin(x, y, xint = NULL, yint = NULL, nxbin = 50, nybin = 50)

Arguments

x

a vector of x values

y

a vector of y values

xint

a vector of x intervals (end values). Defaults to values as specified by pretty(x, n=nxbin)

yint

a vector of y intervals (end values). Defaults to values as specified by pretty(y, n=nybin)

nxbin

number of x bins. Default=50. Not used when xint is defined.

nybin

number of y bins. Default=50. Not used when yint is defined.

Value

A matrix containing interval mid points (x,y), bin frequencies (z), and intervals (xint, yint).

Examples

# Synthetic data
set.seed(1)
n <- 1e6
x <- runif(n, min=-3, max=3)
y <- 4*x^2 + rnorm(n, sd=5)

sqbin.res <- sqbin(x,y)

# Plot
op <- par(mar=c(4,4,1,1))
image(sqbin.res, col=jetPal(20))
par(op)

# Plot with legend
op <- par(no.readonly = TRUE)
lo <- matrix(1:2, nrow=1, ncol=2)
layout(lo, widths=c(4,1), heights=c(4), respect=TRUE)
par(cex=1)
par(mar=c(3,3,1,1))
image(sqbin.res, col=jetPal(20))
par(mar=c(3,0,1,3))
imageScale(sqbin.res$z, col=jetPal(20), axis.pos=4)
par(op)


marchtaylor/sinkr documentation built on July 4, 2022, 5:48 p.m.