1

你好再次亲爱的论坛,

我不是这些 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 :用于着色的变量。...如果指定,它应该是一个与 (x, y, z) 等长的向量。”

所以在我天真的方法中,我检查了

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

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

最好的,玛蒂尔德

4

2 回答 2

2

I also find the colouring scheme a bit difficult. But colvar should be a numeric vector, 1,2,3,4 up to number of groups you have. And then you have to supply col as another vector - having the length of the amount of groups. Scatter3D will then look up each of your numbers in that other vector, supplied as the argument 'col'. E.g.:

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

Now all your colours are made into numbers. And then:

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

That's the col argument where the function can get the colours.

于 2018-02-13T14:26:13.197 回答
0

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

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

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

于 2017-10-24T07:37:17.590 回答