R persp错误:(列表)对象无法强制输入'double'

时间:2016-06-01 12:24:55

标签: r

我是R 3D绘图的新手。我基本上有一个9x3大小的矩阵,矩阵的每个条目都是一个双值:

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

这里我要绘制它们:

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

但是我收到以下错误:

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

它与z矩阵中的double值有关,但我不明白为什么它是一个问题以及如何解决它。

帮助!

1 个答案:

答案 0 :(得分:1)

&#39; z&#39;应该是matrix

 z <- as.matrix(d2)

然后它应该运行。