简体   繁体   中英

R persp Error: (list) object cannot be coerced to type 'double'

I am new to R 3D plotting. I basically have a matrix of size 9x3 and each entry of the matrix is a double value:

390.7269606 390.7330561 390.412666
296.815086  296.5989998 296.6268851
288.4770256 288.3036607 288.3418227
287.4134039 287.2562576 287.3429308
287.0195664 286.8701923 286.9848413
286.832489  286.6888436 286.814465
286.8124387 286.6696583 286.8013845
286.8062249 286.6645971 286.7765071
286.7860349 286.6451203 286.7765071
284.8167037 284.6893261 284.7967308

here what I have to plot them:

###loads the above matrix
d2 <- read.csv("data.csv", header=T, dec=".",sep = " ")
###loads x,y,z
x <- c(2,3,4,5,6,7,8,9,10)
y <- c(3,4,10)
z <- d2
###supposed to draw it!
persp(x, y, z,
  zlab="Score", ylab = "C", xlab="T",
  theta=30, phi=15,ticktype='detailed',
  col="springgreen", shade=0.5)

But I get the following error:

Error in persp.default(x, y, z, zlab = "Score", ylab = "C",  : 
  (list) object cannot be coerced to type 'double'
Calls: persp -> persp.default
Execution halted

It has something to do with the double values in z matrix, but I don't understand why it is an issue and how to solve it.

Help!

The 'z' should be a matrix

 z <- as.matrix(d2)

and then it should run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM