Using some simulated data, this should get you what you want. The key is that you have to create your bivariate bins, accomplished using the cut()
function. Then treating the binned factors as levels we can then count the combinations of each factor level using the table()
function like below:
library(plot3D)
## Simulate data:
set.seed(2002)
x <- rnorm(1000)
y <- rnorm(1000)
## Create cuts:
x_c <- cut(x, 20)
y_c <- cut(y, 20)
## Calculate joint counts at cut levels:
z <- table(x_c, y_c)
## Plot as a 3D histogram:
hist3D(z=z, border="black")
## Plot as a 2D heatmap:
image2D(z=z, border="black")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…