[R] persp plot + plotting grid lines

David Winsemius dwinsemius at comcast.net
Sat Mar 14 19:45:21 CET 2009


Ideas... not a solution. Plot the grid within your ranges using  
something along the lines, literally and figuratively, based on the  
second example of persp's help pages. For the z=8 grid lines on that  
example you could use:

for (ix in seq(-10,10, by=5)) lines (trans3d(x=ix, y=seq(-10,10,  
by=5), z= 8, pmat = res),
                                               col = "red",  
lty="dotted")
for (iy in seq(-10,10, by=5)) lines (trans3d(x=seq(-10,10, by=5),  
y=iy, z= 8, pmat = res),
                                               col = "red",  
lty="dotted")

#for some reason using x and y in the for-loops "contaminated" the x  
and y values in the calling environment. I did not think that was  
supposed to happen.

The concern I see is that the height of the lines and the relation to  
the surface is not apparent to the viewer and the the persp function  
says it ignores transparent colors. I find that contour plots are less  
ambiguous and that the persp plots are most useful for qualitative  
shapes rather than quantitative extraction of inferences. Perhaps in  
your example (not provided) you could draw the grid lines somewhat  
lower and then re-plot plot the surface after plotting the gridlines.  
Since I have not mastered the manner in which persp can be convinced  
to not plot over an existing device in the regions where it has no  
surface, I cannot provide the final steps of that process. The par  
help page describing new= does not make sense to me, and trying both  
TRUE and FALSE fails to achieve the desired results.

One guess is that the way forward might be to adapt the example the  
Sarkar provides at the end of his Lattice book with Figure 13.7:
http://lmdvr.r-forge.r-project.org/figures/figures.html

Or to condition the width of line segments on whether or not they were  
above or below the z-value at z[x=seq(),iy]  or <something else>.?

-- 
David Winsemius


On Mar 14, 2009, at 12:02 PM, Pedro Mardones wrote:

> Dear all;
> Does anyone know how to add grid lines to a persp plot? I've tried
> using lines(trans3d..) but the lines of course are superimposed into
> the actual 3d surface and what I need is something like the plot shown
> in the following link:
> http://thermal.gg.utah.edu/tutorials/matlab/matlab_tutorial.html
> I'll appreciate any ideas
> Thanks
> PM
>
> ______________________________________________
> 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
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list