2014-03-19 79 views
1

我想在R中繪製3D圖,其中y有固定點,x和z是向量。例如:用y作爲點繪製3d,x和z作爲R中的矢量?

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 

任何人都可以幫助我獲得數據繪圖?

+0

你應該得到一個錯誤,當您設置x和z,太。 'x = c(1,2,4,...)'。與z相同 –

回答

2

y對於xz的所有值必須等於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

相關問題