Skip to content
Prev 4750 / 398525 Next

persp() problem

At 22:31 03/03/00 +0100, Troels Ring wrote:

            
simple problem. I have the data shown below
and data.
dates increase and wonder
Dear Troels,

Sure it won't work. The help file ?persp says:

    x, y: locations of grid lines at which the values in `z' are
          measured.  These must be in ascending order.  By default,
          equally spaced values from 0 to 1 are used.  If `x' is a
          `list', its components `x$x' and `x$y' are used for `x' and
          `y', respectively.

       z: a matrix containing the values to be plotted (`NA's are
          allowed).  Note that `x' can be used instead of `z' for
          convenience.


So in your case, vanco must be a matrix. If you do the following:


y <- c(1,2,3,4,4.5)  # the 5 levels of dosis
z <- matrix(data=NA, nrow=length(dates), ncol=length(y))
for (i in 1:length(dates))
{
  j <- which(y == dosis[i])  # get the index of y which value is equal to
the dose
  z[i,j] <- vanco[i]
}

then you get:
[,1] [,2] [,3] [,4] [,5]
 [1,]  3.8   NA   NA   NA   NA
 [2,]  2.4   NA   NA   NA   NA
 [3,]  3.4   NA   NA   NA   NA
 [4,]   NA  7.1   NA   NA   NA
 [5,]   NA  5.3   NA   NA   NA
 [6,]   NA  5.7   NA   NA   NA
 [7,]   NA   NA  7.7   NA   NA
 [8,]   NA   NA  8.3   NA   NA
 [9,]   NA   NA   NA  8.7   NA
[10,]   NA   NA   NA 11.1   NA
[11,]   NA   NA   NA 12.3   NA
[12,]   NA   NA   NA   NA 12.0
[13,]   NA   NA   NA   NA 14.9
[14,]   NA   NA   NA   NA 23.0
[15,]   NA   NA 20.1   NA   NA
[16,]   NA 11.3   NA   NA   NA

though the help says that NA's are allowed, I am not sure that persp() can
deal with such an incomplete matrix. Indeed, I tried:

persp(dates,y,z)

which yielded an empty box. Probably persp() is not the appropriate
function to visualize your data.

Best,

Emmanuel Paradis

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._