Hi, and thanks in advance for any assistance, I'm new to R and to this mailing list, and am having trouble with the * persp()* function. I've got a matrix (z) of values for various combinations of x and y, each of which is a set of (0, 5, 10, 15, 20). But when I try * persp(x,y,z)*, I get an "*invalid z argument*" error, and when I try simply *persp(z)*, R returns an "*invalid x argument*" error, along with warning messages. It seems like a very simple problem, so excuse my ignorance, but any help would be greatly appreciated. Below is the printout from the console. Many thanks, john -------------------------------------------------------- *> x* *[1] 0 5 10 15 20* * * *> y* *[1] 0 5 10 15 20* * * *> z* * [,1] [,2] [,3] [,4] [,5] * *[1,] 4.538 9.169 23.518 32.794 39.322* *[2,] 5.013 13.104 33.282 42.202 45.474* *[3,] 5.296 17.728 36.989 43.89 46.57 * *[4,] 5.366 20.94 39.244 44.987 47.177* *[5,] 5.642 23.396 40.842 45.489 47.126* * * *> persp(x,y,z)* *Error in persp.default(x, y, z) : invalid 'z' argument* * * *> persp(z)* *Error in persp.default(z) : invalid 'x' argument* *In addition: Warning messages:* *1: In min(x, na.rm = na.rm) :* * no non-missing arguments to min; returning Inf* *2: In max(x, na.rm = na.rm) :* * no non-missing arguments to max; returning -Inf* *3: In min(x, na.rm = na.rm) :* * no non-missing arguments to min; returning Inf* *4: In max(x, na.rm = na.rm) :* * no non-missing arguments to max; returning -Inf* *5: In min(x, na.rm = na.rm) :* * no non-missing arguments to min; returning Inf* *6: In max(x, na.rm = na.rm) :* * no non-missing arguments to max; returning -Inf* [[alternative HTML version deleted]]
On Nov 19, 2011, at 3:19 PM, John Benning wrote:> Hi, and thanks in advance for any assistance, > > I'm new to R and to this mailing list, and am having trouble with > the * > persp()* function. I've got a matrix (z) of values for various > combinations > of x and y, each of which is a set of (0, 5, 10, 15, 20). But when I > try * > persp(x,y,z)*, I get an "*invalid z argument*" error, and when I try > simply > *persp(z)*, R returns an "*invalid x argument*" error, along with > warning > messages. It seems like a very simple problem, so excuse my > ignorance, but > any help would be greatly appreciated. Below is the printout from the > console. > > Many thanks, > > john > -------------------------------------------------------- > > *> x* > *[1] 0 5 10 15 20* > * > * > *> y* > *[1] 0 5 10 15 20* > * > * > *> z* > * [,1] [,2] [,3] [,4] [,5] * > *[1,] 4.538 9.169 23.518 32.794 39.322* > *[2,] 5.013 13.104 33.282 42.202 45.474* > *[3,] 5.296 17.728 36.989 43.89 46.57 * > *[4,] 5.366 20.94 39.244 44.987 47.177* > *[5,] 5.642 23.396 40.842 45.489 47.126* > * > * > *> persp(x,y,z)* > *Error in persp.default(x, y, z) : invalid 'z' argument*Unable to reproduce. Maybe z is not a 5 x 5 matrix? > x <-scan() 1: 0 5 10 15 20 6: Read 5 items > y <-scan() 1: 0 5 10 15 20 6: Read 5 items > z <-matrix(scan(),5,5); 1: 4.538 9.169 23.518 32.794 39.322 6: 5.013 13.104 33.282 42.202 45.474 11: 5.296 17.728 36.989 43.89 46.57 16: 5.366 20.94 39.244 44.987 47.177 21: 5.642 23.396 40.842 45.489 47.126 26: Read 25 items > persp(x,y,z) Attached. -------------- next part -------------- A non-text attachment was scrubbed... Name: Rplot.pdf Type: application/pdf Size: 21985 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111119/6cd5cfc0/attachment.pdf> -------------- next part -------------- David Winsemius, MD West Hartford, CT
Your call to persp() is fine, and works just fine for me. Obviously there is something funny about your data (x, y, and z). They must not be numeric (despite appearances). There is something you haven't told us here; how did you obtain/construct x, y, and z? Try the following: x <- y <- 5*(0:4) z <- matrix(scan(textConnection( "4.538 9.169 23.518 32.794 39.322 5.013 13.104 33.282 42.202 45.474 5.296 17.728 36.989 43.89 46.57 5.366 20.94 39.244 44.987 47.177 5.642 23.396 40.842 45.489 47.126")),5,5,byrow=TRUE) closeAllConnections() persp(x,y,z) readline("Go? ") # Or better: persp(x,y,z,theta=-30,phi=40,d=4) cheers, Rolf Turner On 20/11/11 09:19, John Benning wrote:> Hi, and thanks in advance for any assistance, > > I'm new to R and to this mailing list, and am having trouble with the * > persp()* function. I've got a matrix (z) of values for various combinations > of x and y, each of which is a set of (0, 5, 10, 15, 20). But when I try * > persp(x,y,z)*, I get an "*invalid z argument*" error, and when I try simply > *persp(z)*, R returns an "*invalid x argument*" error, along with warning > messages. It seems like a very simple problem, so excuse my ignorance, but > any help would be greatly appreciated. Below is the printout from the > console. > > Many thanks, > > john > -------------------------------------------------------- > > *> x* > *[1] 0 5 10 15 20* > * > * > *> y* > *[1] 0 5 10 15 20* > * > * > *> z* > * [,1] [,2] [,3] [,4] [,5] * > *[1,] 4.538 9.169 23.518 32.794 39.322* > *[2,] 5.013 13.104 33.282 42.202 45.474* > *[3,] 5.296 17.728 36.989 43.89 46.57 * > *[4,] 5.366 20.94 39.244 44.987 47.177* > *[5,] 5.642 23.396 40.842 45.489 47.126* > * > * > *> persp(x,y,z)* > *Error in persp.default(x, y, z) : invalid 'z' argument* > * > * > *> persp(z)* > *Error in persp.default(z) : invalid 'x' argument* > *In addition: Warning messages:* > *1: In min(x, na.rm = na.rm) :* > * no non-missing arguments to min; returning Inf* > *2: In max(x, na.rm = na.rm) :* > * no non-missing arguments to max; returning -Inf* > *3: In min(x, na.rm = na.rm) :* > * no non-missing arguments to min; returning Inf* > *4: In max(x, na.rm = na.rm) :* > * no non-missing arguments to max; returning -Inf* > *5: In min(x, na.rm = na.rm) :* > * no non-missing arguments to min; returning Inf* > *6: In max(x, na.rm = na.rm) :* > * no non-missing arguments to max; returning -Inf* > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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. >
The trailing space (instead of '0') in the third line of the printout of z, the fact that the decimal points are not aligned in the columns, and the left- justification of the column labels are hints that z is not a matrix of numbers, but just prints something like one. *> z* * [,1] [,2] [,3] [,4] [,5] * *[1,] 4.538 9.169 23.518 32.794 39.322* *[2,] 5.013 13.104 33.282 42.202 45.474* *[3,] 5.296 17.728 36.989 43.89 46.57 * E.g., compare the printouts of the following: > pNumeric <- matrix((1:6)*5.125, 3, 2) > pCharacter <- noquote(matrix(as.character((1:6)*5.125), 3, 2)) > pNumeric [,1] [,2] [1,] 5.125 20.500 [2,] 10.250 25.625 [3,] 15.375 30.750 > pCharacter [,1] [,2] [1,] 5.125 20.5 [2,] 10.25 25.625 [3,] 15.375 30.75 This is why R-help encourages people to show datasets using the output of dput(), which shows more of the actual structure of the data. > dput(pNumeric) structure(c(5.125, 10.25, 15.375, 20.5, 25.625, 30.75), .Dim = c(3L, 2L)) > dput(pCharacter) structure(c("5.125", "10.25", "15.375", "20.5", "25.625", "30.75" ), .Dim = c(3L, 2L), class = "noquote") persp() gives odd error messages when x, y, or z is not numeric; it does not just say that character data is not allowed. Try reentering your data and looking at the output of str(z), str(x), and str(y) to make sure they are all numeric and that z is a matrix. > str(pNumeric) num [1:3, 1:2] 5.12 10.25 15.38 20.5 25.62 ... > str(pCharacter) 'noquote' chr [1:3, 1:2] "5.125" "10.25" "15.375" "20.5" "25.625" "30.75" Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of John Benning > Sent: Saturday, November 19, 2011 12:20 PM > To: r-help at r-project.org > Subject: [R] persp() problem > > Hi, and thanks in advance for any assistance, > > I'm new to R and to this mailing list, and am having trouble with the * > persp()* function. I've got a matrix (z) of values for various combinations > of x and y, each of which is a set of (0, 5, 10, 15, 20). But when I try * > persp(x,y,z)*, I get an "*invalid z argument*" error, and when I try simply > *persp(z)*, R returns an "*invalid x argument*" error, along with warning > messages. It seems like a very simple problem, so excuse my ignorance, but > any help would be greatly appreciated. Below is the printout from the > console. > > Many thanks, > > john > -------------------------------------------------------- > > *> x* > *[1] 0 5 10 15 20* > * > * > *> y* > *[1] 0 5 10 15 20* > * > * > *> z* > * [,1] [,2] [,3] [,4] [,5] * > *[1,] 4.538 9.169 23.518 32.794 39.322* > *[2,] 5.013 13.104 33.282 42.202 45.474* > *[3,] 5.296 17.728 36.989 43.89 46.57 * > *[4,] 5.366 20.94 39.244 44.987 47.177* > *[5,] 5.642 23.396 40.842 45.489 47.126* > * > * > *> persp(x,y,z)* > *Error in persp.default(x, y, z) : invalid 'z' argument* > * > * > *> persp(z)* > *Error in persp.default(z) : invalid 'x' argument* > *In addition: Warning messages:* > *1: In min(x, na.rm = na.rm) :* > * no non-missing arguments to min; returning Inf* > *2: In max(x, na.rm = na.rm) :* > * no non-missing arguments to max; returning -Inf* > *3: In min(x, na.rm = na.rm) :* > * no non-missing arguments to min; returning Inf* > *4: In max(x, na.rm = na.rm) :* > * no non-missing arguments to max; returning -Inf* > *5: In min(x, na.rm = na.rm) :* > * no non-missing arguments to min; returning Inf* > *6: In max(x, na.rm = na.rm) :* > * no non-missing arguments to max; returning -Inf* > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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.