[R] persp plot

Chad Junkermeier junkermeier at byu.edu
Tue Jun 24 21:24:04 CEST 2008


Thanks for your reply.

When I did what you said
>
> z <- t(matrix(zdata, nrow = length(ydata)))
> persp(xdata, ydata, z)

I got the following errors:

Error in persp.default(xdata, ydata, z) : invalid 'x' argument
Calls: persp -> persp.default
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
Execution halted






On Jun 24, 2008, at 2:07 PM, Franz Mueter wrote:

> Chad -
>
> I think what you want (after reading in your data) is:
>
> z <- t(matrix(zdata, nrow = length(ydata)))
> persp(xdata, ydata, z)
>
>
> Cheers, Franz
>
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org 
> ] On
> Behalf Of Chad Junkermeier
> Sent: Tuesday, June 24, 2008 7:39 AM
> To: r-help at r-project.org
> Subject: [R] persp plot
>
> I have a set of data in the form
> x1, y1, z1
> x1, y2, z2
> ...
> x1, yN, zN
> x2, y1, z(N+1)
> x2, y2, z(N+2)
> ...
> x2, yN, z(2N)
> ...and so on...
> xM, yN, val(M*N)
>
>
> I have been trying to figure out how to get R to use this data in a
> persp plot.  So far the only thing that I can figure out to do is to
> break the data file into three different files.  The first file
> contains the x-coordinate data:
> x1
> x2
> ...
> xM
> The second file contains the data
> y1
> y2
> ...
> yN
> And finally the last file contains the data for the z-axis.
> z1
> z2
> ...
> z(M*N)
> Once I have the three data files created I use them in the following R
> script:
>
> cat << EOF | R --no-save
> def.par <- par(no.readonly = TRUE)
>
> en_range <- c(-6.2, 0.0)
> om_range <- c(-200.0, 500.0)
> ze_range <- c(0.0, 1.0)
> z_perspective <-c(0,3)
>
> xdata <- scan("x.txt", list(0))
> ydata <- scan("y.txt", list(0))
> zdata <- scan("z.txt", list(0))
>
> f <- function(xdata,ydata) { rr <- zdata; rr }
> z <- outer(xdata, ydata, f)
>
> pdf(file="persp.pdf",height = 8, width =8)
>
> persp(xdata, ydata, z, axes = TRUE, nticks = 5, ticktype =
> "detailed",r=1.5)
>
> dev.off()
>
> q()
>
> EOF
>
> The problem is that when I look at the plot, the peaks of the zdata
> are i
> The problem is that when I look at the plot, the peaks of the zdata
> are in the wrong places on the x axis.  I have carefully looked over
> my data files and I am confident that they are correct.  Thus I
> believe that the error is in my R script; most likely in the following
> lines
>
> f <- function(xdata,ydata) { rr <- zdata; rr }
> z <- outer(xdata, ydata, f)
>
> Do you have any suggestions?
>
>
>
> Chad Junkermeier, Graduate Student
> Dept. of Physics
> West Virginia University
> PO Box 6315
> 210 Hodges Hall
> Morgantown WV 26506-6315
> -----------------------------------------------------
> Concurrently at:
> Dept. of Physics and Astronomy
> Brigham Young University
> Provo UT 84602
>
>
> 	[[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