2

I'm struggling with scatter3D from plot3D package.

I would like to be able to put a transparency threshold on my colvar. For example, below, I should have every point with the colvar<100 (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 ?

enter image description here

Here are my datas : http://s000.tinyupload.com/?file_id=00763309738825363461

And my code :

err_tab2=read.table("Err_tab.txt",header=T)

colfunc<-colorRampPalette(c("red","yellow","green","turquoise2","blue"))


  par(mfrow = c(1, 1))
  panelfirst <- function(pmat) {
    zmin <- min(err_tab2$z)
    XY <- 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 <- min(err_tab2$x)
    XY <- 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<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))
  )

Note : In fact I would like to have a condition for each point like :

alpha=(err_tab2$colour-min(err_tab2$colour))/(max(err_tab2$colour)-min(err_tab2$colour))>0.2

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

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

enter image description here

Any idea ? :)

R_SOF
  • 268
  • 1
  • 7

1 Answers1

0

Here is the answer I was looking for. To filter only points with a value in the first 20% of the set :

col_level=sort(as.numeric(levels(as.factor(err_tab2$colour))))

with(err_tab2, scatter3D(x = x, y = y, z = z, colvar= (colour), col=alpha.col(colfunc(length(colour)),
                               alpha =(col_level-min(col_level))/(max(col_level)-min(col_level))<0.20)),
                               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))
)
R_SOF
  • 268
  • 1
  • 7