【问题标题】:R - 3Dplot - adding a condition on transparencyR - 3Dplot - 添加透明度条件
【发布时间】:2016-07-25 08:16:30
【问题描述】:

我正在努力处理来自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

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

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

有什么想法吗? :)

【问题讨论】:

    标签: r transparency alpha threshold scatter3d


    【解决方案1】:

    这是我一直在寻找的答案。 只过滤值在集合的前 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))
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-18
      • 2012-01-02
      相关资源
      最近更新 更多