hist2d {JOPS} | R Documentation |
Compute a 2D histogram
Description
Compute a two-dimesnional histogram from two vectors (of the same length), x
and y
.
Usage
hist2d(x, y, nb = c(100, 100), xlim = range(x), ylim = range(y))
Arguments
x |
a numeric vector. |
y |
a numeric vector of the same length as |
nb |
a vector |
xlim |
a vector |
ylim |
a vector |
Details
If nb
is scalar, it is extended to c(nb, nb)
, so that both dimensions will have the same number of bins.
Elements of x
(y
) that fall outside the range specified by xlim
(ylim
) are not counted.
Value
A list with components:
H |
a matrix of dimension |
xgrid |
a vector of length |
ygrid |
a vector of length |
xbin |
a vector giving the bin number of each element of |
ybin |
a vector giving the bin number of each element of |
References
Eilers, P.H.C. and Marx, B.D. (2021). Practical Smoothing, The Joys of P-splines. Cambridge University Press.
Examples
data(faithful)
x = faithful$eruptions
y = faithful$waiting
C = hist2d(x, y, c(50,50))
image(C$xgrid, C$ygrid, C$H, xlab='Eruption length (min)', ylab='Waiting time (min)')
title('Old Faithful geyser')