title: 3d scatterplot with colored spheres with R and Rgl
body: <p>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. </p>
  
  <h1>Edit:</h1>
  
  <p>I created the following code:</p>
  
  <pre><code>library(rgl)
  m &lt;- read.csv(file="mem0.csv", sep = ",", head=TRUE)
  mcol = m$val
  i = 1 
  mdim = dim(m)
  
  while (i &lt;= 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)
  </code></pre>
  
  <h1>Edit number 2:</h1>
  
  <p>I use the rgl.snapshot() to export to an svg file:</p>
  
  <p><img src="https://i.stack.imgur.com/JAMih.png" alt="a snapshot of my rgl.shanpshot"></p>
  
  <p>The data should display a layer of red balls, 4 layers of blue balls and a layer of red balls again. </p>