用y绘制3d作为点,x和z作为R中的向量?

时间:2014-03-19 07:09:59

标签: r plot

我想在R中绘制3D图形,其中y具有固定点,x和z是矢量。例如:

x=[1,2,4,8,16,32,64]
y=0
z=[100,200,300,400,500,600,700]

x=[1,2,4,8,16,32,64]
y=1
z=[...] // 7 points

依此类推,直到y = 10

我尝试使用wireframe,其中y = 1,我总是有这样的错误:

Error in eval(substitute(groups), data, environment(formula)) : 
  numeric 'envir' arg not of length one

有人可以帮助我绘制数据吗?

1 个答案:

答案 0 :(得分:2)

对于yx的所有值,

z必须等于1才能在3D中绘制。它必须是matrix形式。

> x <- c(1,2,4,8,16,32,64)
> y <- rep(1, 7)
> z <- c(100,200,300,400,500,600,700)
> d <- matrix(c(x, y, z), 7, 3)
> d
##      [,1] [,2] [,3]
## [1,]    1    1  100
## [2,]    2    1  200
## [3,]    4    1  300
## [4,]    8    1  400
## [5,]   16    1  500
## [6,]   32    1  600
## [7,]   64    1  700

> library(lattice)
> wireframe(d, scales = list(arrows = FALSE),
            drape = TRUE, colorkey = TRUE,
            screen = list(z = 30, x = -60))

enter image description here