【问题标题】:colvar in scatter3D return error " clim[2] - clim[1] : non-numeric argument to binary operator"scatter3D 中的 colvar 返回错误“clim[2] - clim[1]:二进制运算符的非数字参数”
【发布时间】:2017-01-27 09:50:53
【问题描述】:

你好亲爱的论坛,

我不是这些 3D 情节最好的朋友,而且我在简单的格式设置方面遇到了困难。就像现在一样,我无法从变量中为绘图着色。

with(samples3d, {
  s3d <- scatter3D(MDS2, MDS3, MDS1, pch = ifelse(meta$op.closed=="cl",22,21), type = "h",colvar = pcolor, lty.hplot=2, scale.y=0.75)
 } )

它给了我这个错误:

Error in clim[2] - clim[1] : non-numeric argument to binary operator

我可以从文档中读到:

"colvar : 用于着色的变量。 ... if 指定时,它应该是一个与 (x, y, z) 等长的向量。”

所以在我的幼稚方法中我检查了

colvec <- as.vector(samples3d$pcolor)
MDS1vec <- as.vector(samples3d$MDS1)
length(MDS1vec)
43
length(colvec)
43

-它们的长度相同,那么这里有什么问题?

最好, 玛蒂尔德

【问题讨论】:

    标签: scatter3d


    【解决方案1】:

    我也发现配色方案有点困难。但是 colvar 应该是一个数字向量,1,2,3,4 最多您拥有的组数。然后你必须提供 col 作为另一个向量 - 长度为 组的数量。然后,Scatter3D 将在另一个向量中查找您的每个数字,作为参数“col”提供。例如:

    colvar <- as.numeric(as.factor(pcolor))
    

    现在你所有的颜色都变成了数字。然后:

    col <-levels(as.factor(pcolor))
    

    这是函数可以获取颜色的 col 参数。

    【讨论】:

      【解决方案2】:

      在不知道向量中包含哪种数据的情况下,我会从错误消息中假设您的 pcolor 向量是非数字的。

      这里给出了此错误消息的详细答案: Non-numeric Argument to Binary Operator Error in R

      一种解决方案可能是使用数值在 pcolor 中对您的组进行编码。当我遇到这个问题时,至少这对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-15
        • 2018-01-20
        • 1970-01-01
        • 2016-06-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多