One quick idea is to use the functions
- contourLines() to calculate the contour lines
- trans3d() to transform the 3D coordinates into the 2D space you will
be plotting into
- polygon() to plot the contour lines
Uwe Ligges
Jack Siegrist wrote:> Hello folks,
>
> I am a beginner R user. I have been able to make a 3D surface plot using
> 'persp'. The surface is made by a grid of lines emanating
perpendicularly
> from each of the x and y axes at regular intervals.
>
> I can get rid of that grid by setting 'border=NA'.
>
> Can anyone suggest some ways to replace the grid with contour lines, to
> create a 3-dimensional contour map?
>
> Thanks for any help.
>
> Here is an example of what I have so far:
>
> #to create a perspective plot; plots funct. across all combos of x and y
>
> 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,col='lightgray',shade=.5,border=NA,) #plots without
gridlines
>
> ______________________________________________
> 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.