hist2d | R Documentation |
Compute a two-dimesnional histogram from two vectors (of the same length), x
and y
.
hist2d(x, y, nb = c(100, 100), xlim = range(x), ylim = range(y))
x |
a numeric vector. |
y |
a numeric vector of the same length as |
nb |
a vector |
xlim |
a vector |
ylim |
a vector |
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.
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 |
Eilers, P.H.C. and Marx, B.D. (2021). Practical Smoothing, The Joys of P-splines. Cambridge University Press.
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.