[R] contour & persp
Peter Ehlers
ehlers at ucalgary.ca
Tue Feb 9 14:53:56 CET 2010
Further to Uwe's answer: I suspect that you're not telling us
the whole story (that's why it's so useful to have reproducible
code).
Try this:
x <- y <- 1:3
z <- outer(x, y)
z[1,1] <- 1/0
persp(x,y,z)
which results in:
Error in persp.default(x, y, z) : invalid 'z' limits
So, are some your 'NaN's actually 'Inf's?
-Peter Ehlers
Uwe Ligges wrote:
>
>
> On 07.02.2010 22:46, Andrew Wang wrote:
>> I have this data set that both x& y are ordered vectors of length
>> 600& 700 respectively; z is a 600 by 700 matrix whose entry z[i,j] is
>> either a missing value (indicated by 'NaN') or a real number between 0
>> and 1. The contour function
>>
>> contour(x,y,z)
>>
>> gives me a blank picture. I guess the reason is that most of z-entries
>> are missing, only less than 1% are non missing.
>>
>> Question (1)
>>
>> Is there a way that I could manipulate the data or function to have
>> the non-missing values plotted?
>>
>> Also, trying function "persp" gives me this error message
>>
>> persp(x,y,z)
>>
>> Error in persp.default(x, y, z) : invalid 'z' limits
>>
>> I look at the manual of "persp". I guess, the error message comes from
>> its internal call
>>
>> zlim = range(z, na.rm = TRUE)
>>
>> it appears to me that "persp" can't handle missing value yet its
>> manual states clearly
>>
>> z: a matrix containing the values to be plotted ('NA's are
>> allowed). Note that ‘x’ can be used instead of ‘z’
>> for convenience.
>>
>>
>> Question (2)
>>
>> Can "persp" handle missing values in z? if the answer is a sounding
>> "yes", how should I do in my case?
>
>
>
>
> Works for me:
> persp(1:2, 1:2, matrix(c(1:3, NA), nrow=2))
>
>
> Hence you really need to specify an example where it does not work.... -
> as the posting guide asks you to do anyway.
>
> Uwe Ligges
>
>
>
>> Please help, Thanks!
>>
>> Your frustrated
>>
>> Andrew
>>
>>
>>
>>
>> ______________________________________________
>> 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.
>
> ______________________________________________
> 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.
--
Peter Ehlers
University of Calgary
More information about the R-help
mailing list