В пакете rgl есть функция hist3d (на самом деле это не документ, но вы можете вызвать его и увидеть код).
Хотя для этого отображается Hist3D, для меня отображается2-мерные гистограммы (input = x, y) в 3-х измерениях.
Если это то, что вам нужно, вот код (из rgl):
> hist3d
function(x,y=NULL,nclass="auto",alpha=1,col="#ff0000",scale=10)
{
save <- par3d(skipRedraw=TRUE)
on.exit(par3d(save))
xy <- xy.coords(x,y)
x <- xy$x
y <- xy$y
n<-length(x)
if (nclass == "auto") { nclass<-ceiling(sqrt(nclass.Sturges(x))) }
breaks.x <- seq(min(x),max(x),length=(nclass+1))
breaks.y <- seq(min(y),max(y),length=(nclass+1))
z<-matrix(0,(nclass),(nclass))
for (i in 1:nclass)
{
for (j in 1:nclass)
{
z[i, j] <- (1/n)*sum(x < breaks.x[i+1] & y < breaks.y[j+1] &
x >= breaks.x[i] & y >= breaks.y[j])
binplot.3d(c(breaks.x[i],breaks.x[i+1]),c(breaks.y[j],breaks.y[j+1]),
scale*z[i,j],alpha=alpha,topcol=col)
}
}
}
Я построил свой собственный Hist3Dдля возврата трехмерной гистограммы (например, для использования в Red Green Blue):
my_hist3d <- function(x,y=NULL,z=NULL, nclass="auto",alpha=1,col="#ff0000",scale=10)
{
xyz <- xyz.coords(x,y,z)
x <- xyz$x
y <- xyz$y
z <- xyz$z
n<-length(x)
if (nclass == "auto") { nclass<-ceiling(sqrt(nclass.Sturges(x))) }
breaks.x <- seq(min(x),max(x),length=(nclass+1))
breaks.y <- seq(min(y),max(y),length=(nclass+1))
breaks.z <- seq(min(z),max(z),length=(nclass+1))
h = array(1:(nclass^3), dim=c(nclass,nclass,nclass))
for (i in 1:nclass)
{
for (j in 1:nclass)
{
for (k in 1:nclass)
{
h[i,j,k] <- (1/n)*sum(x < breaks.x[i+1] & y < breaks.y[j+1] & x >= breaks.x[i] & y >= breaks.y[j] & z < breaks.z[k+1] & z >= breaks.z[k])
}
}
}
return(h)
}
Возвращаемая переменная (h) представляет собой трехмерную матрицу размера nclass ^ 3 (nclass - это число биновв каждом измерении).