[R] persp Error. x,y,z with the same length

Duncan Murdoch murdoch at stats.uwo.ca
Wed Apr 11 18:01:19 CEST 2007


Felix Wave wrote:
> Hello,
> I have a problem in drawing a 3d graphic. I simplified the program to show you the problem.
>
> I have a text file with hundreds of entries in 3 columns. I scaned these columns with matrix(scan). Then, I transformed some datas. Now I have the datas in h,x,y. 
> I created a new matrix to use persp . But I got an error. The reason is probably the same length of x,y,z. 
>
> But what can I do the draw my datas in a 3d graphic? (I want to use persp resp. image)
>   

persp is for drawing a surface, not a 3d scatterplot.  If the points are 
somehow distributed on a surface, you
need to convert them to the format persp expects:  z in a rectangular 
matrix of values, x and y giving row and column values.  The interp() 
function in the akima package can do this.

If you want a 3d scatterplot, you can use the plot3d function in rgl, or 
scatterplot3d in the package of the same name.

Duncan Murdoch
> Thanks a lot!
> Felix
>
>
> the code:
> ------------
> h   <- Measure3[,4]
> x   <- Measure3[,3]
> y   <- Measure3[,2]
>
> z   <- matrix(c(x,y,h),ncol=3)
> z
>
> persp(x, y, z)
>
>
>   
>> z
>>     
>       [,1] [,2]        [,3]
>  [1,]  0.0    0 0.000000000
>  [2,]  0.1    0 0.000538990
>  [3,]  0.2    0 0.002315760
>  [4,]  0.3    0 0.005333315
>  [5,]  0.4    0 0.009595005
>  [6,]  0.5    0 0.015104450
>  [7,]  0.6    0 0.021865495
>  [8,]  0.7    0 0.029882130
>  [9,]  0.8    0 0.039158475
> [10,]  0.9    0 0.049698760
>
> Default in persp.default(x, y, z) : increasing 'x' and 'y' values expected
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list