[R] Re: persp() problem
Emmanuel Paradis
paradis at isem.univ-montp2.fr
Sat Mar 4 16:02:46 CET 2000
At 22:31 03/03/00 +0100, Troels Ring wrote:
>Dear friends. A very humble admirer of the progress of R with a very
simple problem. I have the data shown below
>
>month day year dosis vanco
>12 31 1999 1 3.8
>1 3 2000 1 2.4
>1 7 2000 1 3.4
>1 12 2000 2 7.1
>1 14 2000 2 5.3
>1 17 2000 2 5.7
>1 19 2000 3 7.7
>1 21 2000 3 8.3
>1 24 2000 4 8.7
>1 26 2000 4 11.1
>1 31 2000 4 12.3
>2 7 2000 4.5 12.0
>2 14 2000 4.5 14.9
>2 18 2000 4.5 23.0
>2 25 2000 3 20.1
>2 28 2000 2 11.3
>
>dates <- mdy.date(month,day,year)
>persp(dosis,dates,vanco)
>-- trying to produce a three demensional picture of vancomycin versus dose
and data.
>but: Error in persp(dosis, dates, vanco) : increasing x and y values expected
>Dates is increaing, and I couldnot figure out how to make both dosis and
dates increase and wonder
>how to produce a surface in this situation.
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:
> z
[,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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list