Mathilde
Mathilde

Reputation: 321

colvar in scatter3D return error " clim[2] - clim[1] : non-numeric argument to binary operator"

Hallo again dear forum,

I am not the best of friends with these 3D plots, and I struggle with simple formatting stuff. Like now, where I can't color my plots from a variable.

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

It gives me this error:

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

I can read from the documentation that:

"colvar :The variable used for coloring. ... if specified, it should be a vector of equal length as (x, y, z)."

So in my naïve approach I checked

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

- and they are the same length, so what is wrong here?

Best, Mathilde

Upvotes: 1

Views: 874

Answers (2)

lasse
lasse

Reputation: 21

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.

Upvotes: 2

Magnus Hallas
Magnus Hallas

Reputation: 23

Without knowing what kind of data is in your vectors, I would assume from the error message that your pcolor vector is non-numeric.

A detailed answer to this error message is given here: Non-numeric Argument to Binary Operator Error in R

A solution could be to code your groups in pcolor with numeric values. At least that worked for me, when I had this problem.

Upvotes: 0

Related Questions