R - 3Dplot - 添加透明度条件

R - 3Dplot - adding a condition on transparency

我正在为 plot3D 包裹中的 scatter3D 而苦苦挣扎。

我希望能够为我的 colvar 设置透明度阈值。例如,在下面,我应该让带有 colvar<100 的每个点(从红色到绿色中间)完全透明。我不明白为什么一半的 colkey(和相应的点 ;))没有消失。 你有什么想法吗?

这是我的数据: http://s000.tinyupload.com/?file_id=00763309738825363461

还有我的代码:

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))
  )

注意:事实上,我希望每个点都有一个条件,例如:

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

在我看来,这应该隐藏 "colour" 属于集合前 20% 的每个点。因为 F=0=100%transparencyT=1=100%opacity.

但是如果我尝试这个,我会得到完全相反的结果(我猜是添加到之前的问题):

有什么想法吗? :)

这是我一直在寻找的答案。 仅过滤值在集合的前 20% 中的点:

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))
)