[R] persp() problem

Petr PIKAL petr.pikal at precheza.cz
Tue Sep 11 18:28:06 CEST 2007


Hi

He is actually plotting DM matrix against default values [0,1]. So what he 
needs to do is to change y to c(1,10) and x to seq(1,20,2) to enable his 
code work. And even in that case there is not possible AFAIK to control 
exact labeling of axes as they are internaly recalculated to [0,1] values.

Petr
petr.pikal at precheza.cz

r-help-bounces at r-project.org napsal dne 11.09.2007 17:42:07:

> 
> There is an error in your code:
> in persp(x , y , z) the length of x is the number of rows of z, the 
length
> of y is the number of columns of z,
> You should also name the rows and columns in z with x and y 
> 
> 
> 
> Economics Guy wrote:
> > 
> > I am having some trouble getting the persp() package to change the x
> > and y axis on a 3d plot. It defaults to the [0,1] interval and when I
> > try to change it I get errors.
> > 
> > Example:
> > 
> > This works:
> > ------------
> > D <- c(1,2,3,4,5,6,7,8,9,10)
> > M <- c(11,12,13,14,15,16,17,18,19,20)
> > 
> > DM <- cbind(D,M)
> > 
> > persp(DM, theta = 40, phi = 30, expand = 0.5, col = "lightblue",
> >       ltheta = 120, shade = 0.75, ticktype = "detailed",
> >       xlab = "X", ylab = "Y", zlab = "Z")
> > ---------------------
> > 
> > 
> > But I want the axis to count 1 by ones. So I try:
> > -----------------
> > D <- c(1,2,3,4,5,6,7,8,9,10)
> > M <- c(11,12,13,14,15,16,17,18,19,20)
> > 
> > DM <- cbind(D,M)
> > 
> > x <- 1*0:10
> > y <- 1*0:20
> > persp(x,y,DM, theta = 40, phi = 30, expand = 0.5, col = "lightblue",
> >       ltheta = 120, shade = 0.75, ticktype = "detailed",
> >       xlab = "X", ylab = "Y", zlab = "Z")
> > -------------------------
> > 
> > I get:
> > 
> > Error in persp(x, y, z, xlim, ylim, zlim, theta, phi, r, d, scale,
> > expand,  : invalid 'z' argument
> > 
> > but the z was fine in the first version so I am not sure what the deal 
is.
> > 
> > Any ideas?
> > 
> > -Econ Guy
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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.
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/persp%28%29-problem-
> tf4417956.html#a12617657
> 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.



More information about the R-help mailing list