[R] persp() problem

Rolf Turner rolf.turner at xtra.co.nz
Sat Nov 19 22:48:01 CET 2011


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.
>



More information about the R-help mailing list