[R] error with persp()- increasing 'x' and 'y' values expected
David L Carlson
dcarlson at tamu.edu
Tue Feb 21 18:07:47 CET 2012
You do not have your data organized in a way that persp() can use it. Here
is a simple example. The function will not work with x, y, z vectors. X and
Y are vectors in order with no repeated values, Z is a matrix containing one
value for every combination of x and y:
> x <- 1:10
> y <- 1:15
> z <- outer(x, y, "*")
> persp(x, y, z)
You must define a grid and specify a single value at each point on that
grid.
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of David Winsemius
Sent: Monday, February 20, 2012 10:09 PM
To: adick
Cc: r-help at r-project.org
Subject: Re: [R] error with persp()- increasing 'x' and 'y' values expected
On Feb 20, 2012, at 5:49 PM, adick wrote:
>
> On Feb 20, 2012, at 2:15 PM, adick wrote:
>
> Do you have missing entries? (Running your data fragment through your
> code produces the same error.) You may want to use rep with each and
> times arguments to construct a regular grid and then population the
> missing entries in matrix with NA's.
>
>
>
> Yes, there are missing entries. I don't know what rep and times
> arguments
> are or how to do anything you just said, because I'm knew to R.
?rep
> rep(1:3, times=3)
[1] 1 2 3 1 2 3 1 2 3
> rep(1:3, each=3)
[1] 1 1 1 2 2 2 3 3 3
You can also use gl
?gl
--
David.
>
> I did however figure out how to take the average of my three
> replicates and
> try to plot that, which returns the same error. Here is the updated
> code:
>
> bob= scan ("SBA3dataTaxonB.txt",what="char")
> labels = bob[1:3]
> bob=bob[-c(1,2,3)]
> bob=as.numeric(bob)
> bob=array(bob,dim=c(3, length(bob)/3))
> bob=t(bob)
> data.frame(bob) -> bob
> vary=0
> varx= 0
> varz=0
>
> for (r in 1:(length(bob[,1])/3)) {
> vary[r] <- mean(bob[(1+((r-1)*3)):(3+((r-1)*3)),2])
> varx[r] <- bob[(1+((r-1)*3)),1]
> varz[r] <- bob[(1+((r-1)*3)),3]
> }
> rob <- data.frame(varx=varx,varz=varz,vary=vary)
>
> rob = rob[order(rob[,1], rob[,2]),]
> persp(rob[,1], rob[,2], rob[,3], log="rob[,1]")
>
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/error-with-persp-increasing-x-and-y-values-exp
ected-tp4404834p4405380.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
______________________________________________
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