4

I have a set of values, w, for each (x,y,z). I want to visualize this 4D data as an interactive 3D image plot.

That is, each 3D pixel x,y,z should get some color based on w.

PS: w ranges from 0-7, and the rest of the (x,yz) are just transparent.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
r00kie
  • 843
  • 1
  • 11
  • 12
  • 4
    If you just throw some from-head sample data... But [rgl](http://cran.r-project.org/web/packages/rgl/index.html) should help. Try `install.packages("rgl"); require(rgl); demo(rgl)` – Marek Aug 05 '11 at 05:30
  • Take a look at the two answers here: http://stackoverflow.com/questions/6774777/how-to-change-points-and-add-a-regression-to-a-cloudplot-using-r/6775352#6775352 Use the color/colour parameters to add the 4th dimension. – Ari B. Friedman Aug 05 '11 at 06:44
  • Something like this? http://stackoverflow.com/questions/5972527/r-xy-scatter-plot-in-3d-using-density – Roman Luštrik Aug 05 '11 at 06:50
  • I tried them, I can plot 3D points with different colors. But I am looking for a 3D volume plot (analogous to a 2D image plot, where (x,y) are co-ordinates and z is pixel value). Here (x,y,z) are co-ordinates and w is pixel value. – r00kie Aug 05 '11 at 10:04
  • `rgl::surface3d` maybe (see demo that Marek noted)? – Roman Luštrik Aug 05 '11 at 10:12
  • I suspect this is nearly an exact duplicate: http://stackoverflow.com/questions/3786189/r-4d-plot-x-y-z-colours – joran Aug 05 '11 at 13:53

1 Answers1

1

Here is an example. Note that your z data needs to be a matrix with x rows and y columns.

library(rgl)
set.seed(1)
x <- seq(1,10)
y <- seq(1,10)
w <- runif(100)
z <- runif(100)

wcolors <- rainbow(length(w))[rank(w)]
zmat <- matrix(z, length(x),length(y))

persp3d(x=x, y=y, z=zmat, col = wcolors)
Zach
  • 29,791
  • 35
  • 142
  • 201