[R] Contour lines in a persp plot
David Winsemius
dwinsemius at comcast.net
Thu May 16 18:58:47 CEST 2013
On May 16, 2013, at 8:23 AM, smsome at univ-fcomte.fr wrote:
> Hello folks,
>
> i'm a R beginner and i want to put in a same plot both contour lines and persp plot.
>
> For example,
>
> fn<-function(x,y){sin(x)+2*y} #this looks like a corrugated tin roof
>
> x<-seq(from=1,to=100,by=1) #generates a list of x values to sample
> y<-seq(from=1,to=100,by=1) #generates a list of y values to sample
>
> z<-outer(x,y,FUN=fn) #applies the funct. across the combos of x and y
>
> persp(z) #plots without gridlines
> contour(z) # for contour lines
>
> i want this in a same plot.
> Can anyone help me, i have no more idea to try this.
Ideas: I can tell you that I have seen an example that projects contour lines on one of the pseudo-3d coordinate planes of a wireframe (lattice) plot in Sarkar's Lattice book. (All of those examples are on the web and a google search: lattice wireframe contour plot … is immediately productive of a citation to Figure 13.7 as well as links to the Rhelp archive.) To do something similar I imagine you would need to do work with the coordinate transform function, ?trans3d, described on the ?persp page and use as input the results from ?contourLines.
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list