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) 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
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. >
x and y should be vectors with the coordinates, z should be a matrix with the heights at the combination of those coordinates. If x and y are properly gridded in your dataset, then try something like:> h <- Measure3[,4] > x <- sort(unique(Measure3[,3])) > y <- sort(unique(Measure3[,2])) > z <- matrix( h, ncol=length(x) ) > persp(x,y,z)Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Felix Wave > Sent: Wednesday, April 11, 2007 8:56 AM > To: r-help at stat.math.ethz.ch > Subject: [R] persp Error. x,y,z with the same length > > 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) > > 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. >