R - 3Dplot - adding a condition on transparency
<p>I'm struggling with <code>scatter3D</code> from <code>plot3D</code> package.</p>

<p>I would like to be able to put a transparency threshold on my colvar. For example, below, I should have every point with the <code>colvar&lt;100</code> (so from red to the middle of green) fully transparent. I don't understand why not half of the colkey (and the corresponding points ;) ) disappear.
Do you have an idea ?</p>

<p><a href="https://i.stack.imgur.com/VYYpf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VYYpf.png" alt="enter image description here"></a></p>

<p>Here are my datas :
<a href="http://s000.tinyupload.com/?file_id=00763309738825363461" rel="nofollow noreferrer">http://s000.tinyupload.com/?file_id=00763309738825363461</a></p>

<p>And my code :</p>

<pre><code>err_tab2=read.table("Err_tab.txt",header=T)

colfunc&lt;-colorRampPalette(c("red","yellow","green","turquoise2","blue"))


  par(mfrow = c(1, 1))
  panelfirst &lt;- function(pmat) {
    zmin &lt;- min(err_tab2$z)
    XY &lt;- trans3D(err_tab2$x, err_tab2$y,
                  z = rep(zmin, nrow(err_tab2)), pmat = pmat)
    scatter2D(XY$x, XY$y, colvar = err_tab2$colour, pch = ".",
              cex = 1, add = TRUE, colkey = FALSE)
    xmin &lt;- min(err_tab2$x)
    XY &lt;- trans3D(x = rep(xmin, nrow(err_tab2)), y = err_tab2$y,
                  z = err_tab2$z, pmat = pmat)
    scatter2D(XY$x, XY$y, colvar = err_tab2$colour, pch = ".",
              cex = 1, add = TRUE, colkey = FALSE)
  }

  with(err_tab2, scatter3D(x = x, y = y, z = z, colvar= (colour), col=alpha.col(colfunc(length(colour)),
                                                                                alpha =colour&lt;100),
                           pch = 16, cex = 1, xlab = "x", ylab = "y",
                           zlab = "z", clab = c(""),
                           main = paste("Model"), ticktype = "detailed",
                           panel.first = panelfirst, theta = 330,phi=10, y = 2,
                           colkey = list(length = 0.5, width = 0.5, cex.clab = 0.75))
  )
</code></pre>

<p>Note : In fact I would like to have a condition for each point like :</p>

<pre><code>alpha=(err_tab2$colour-min(err_tab2$colour))/(max(err_tab2$colour)-min(err_tab2$colour))&gt;0.2
</code></pre>

<p>In my mind, this should hide every point for which "colour" belong to the first 20% of the set. Because <code>F=0=100%transparency</code> and <code>T=1=100%opacity</code>.</p>

<p>But if I try this, I obtain the exact opposite (added to previous problem I guess) : </p>

<p><a href="https://i.stack.imgur.com/QlCEt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QlCEt.png" alt="enter image description here"></a></p>

<p>Any idea ? :)</p>