I want to create a 3d scatter plot of spheres with their color being the fourth dimension. I have the data in a csv file where each line indicates the x,y,z position of a particle and I have a column which tells me the value of the particle (1,2 or 3). I want to color the balls in one color if their value is 1 or in another color otherwise.
Edit:
I created the following code:
library(rgl)
m <- read.csv(file="mem0.csv", sep = ",", head=TRUE)
mcol = m$val
i = 1
mdim = dim(m)
while (i <= mdim[1] ){
if (mcol[i] == 1){
mcol[i] = "red"
}else {
mcol[i] = "blue"
}
i = i +1
}
plot3d(m$x, m$y, m$z, col = mcol, type='s', size=0.1)
Edit number 2:
I use the rgl.snapshot() to export to an svg file:
The data should display a layer of red balls, 4 layers of blue balls and a layer of red balls again.
The
plot3d()
function of thergl
package allows to do such a thing quite easily. And you can even explore your plot interactively :You can call
plot3d()
like this :Which will give you something like :