I want to plot a 3D array M where
M <- array(runif(64),dim=c(4,4,4))
A similar question is here with comments that this can be done using a common 3D plot in R, but I could find no such function in R which can be used to plot multidimensional arrays (say, a 3D array as in the above example). Any suggestion how to do it? Thanks.
Use melt to create a table of x,y,z,value, and then rgl to do a 3d plot:
library(reshape2)
library(rgl)
M=melt(M)
points3d(M$Var1,M$Var2,M$Var3)
That's just 64 points in a cube. You can scale and colour them:
points3d(M$Var1,M$Var2,M$Var3,size=10,color=rainbow(10)[M$value*10])
Use whatever method of mapping M$value to colour you prefer. Don't use rainbow palettes for real!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With