[R] Creating 3D Gaussian Plot

Duncan Murdoch murdoch at stats.uwo.ca
Sat Jan 28 17:30:25 CET 2006


On 1/28/2006 9:52 AM, Laura Quinn wrote:
> I'm working from a blank canvas! The perspective isn't key - the most
> important thing is getting the values for the grid mesh points, the method
> of plotting is less crucial. I was hoping there might be an inbuilt R
> function which would allow me to create the grid points by specifying
> amplitude/wavelength parameters but my searches have come up blank thus
> far. I'd happily knock up a FORTRAN routine to provide me with the coords
> for the gridpoints, but I can't figure out the underlying equation.

Supposing you want the peaks at (1,-1) and (-1,1), a reasonable equation 
might be

fn <- function(x, y, scale) 
dnorm(x,mean=1,sd=scale)*dnorm(y,mean=-1,sd=scale) - 
dnorm(x,mean=-1,sd=scale)*dnorm(y,mean=1,sd=scale)

Then you can plot it on a grid by

x <- seq(-4,4,len=100)
y <- seq(-4,4,len=100)
z <- outer(x,y,fn,scale=0.5)
persp(x,y,z,col="green",border=NA,shade=0.75)

You can play around with the arguments to persp to change the colours, 
rotate it, etc.  The scale argument controls how pointy the peaks are.

You might also want to look at the surface3d function in the rgl 
package.  It does scaling differently, so you'd probably want something like

bg3d("white")
surface3d(x,y,z*6,col="green")

which gives a surface like the one above, but you can rotate it using 
the mouse.

Duncan Murdoch

> 
> Laura Quinn
> Institute of Atmospheric Science
> School of Earth and Environment
> University of Leeds
> Leeds
> LS2 9JT
> 
> tel: +44 113 343 1596
> fax: +44 113 343 6716
> mail: laura at env.leeds.ac.uk
> 
> On Sat, 28 Jan 2006, Duncan Murdoch wrote:
> 
>> On 1/28/2006 9:27 AM, Laura Quinn wrote:
>>> My apologies.
>>>
>>> With further apologies for the poor graphics, this link demonstrates the
>>> sort of 3d mesh which I am hoping to replicate - I would like to be able
>>> to replicate a number of these of varying intensity. Demonstrating
>>> different levels of potential via the "steepness" of the slopes.
>>>
>>> http://maxwell.ucdavis.edu/~electro/potential/images/steep.jpg
>>>
>>> I then wish to pick a number of grid points at random from the output to
>>> perform a further analysis upon.
>>>
>>> I hope this makes things a little clearer!
>>>
>>> Again, any help gratefully received, thank you.
>> That's helpful.  You can produce a graph like that using persp(),
>> provided you have already calculated the values at all the points on the
>> grid -- but it sounds as though you haven't got those yet.  What sort of
>> input do you have?
>>
>> Duncan Murdoch
>>>
>>> Laura Quinn
>>> Institute of Atmospheric Science
>>> School of Earth and Environment
>>> University of Leeds
>>> Leeds
>>> LS2 9JT
>>>
>>> tel: +44 113 343 1596
>>> fax: +44 113 343 6716
>>> mail: laura at env.leeds.ac.uk
>>>
>>> On Sat, 28 Jan 2006, Duncan Murdoch wrote:
>>>
>>>> On 1/28/2006 8:55 AM, Laura Quinn wrote:
>>>>> Hello,
>>>>>
>>>>> I requested help a couple of weeks ago creating a dipole field in R but
>>>>> receieved no responses. Eventually I opted to create a 3d sinusoidal plot
>>>>> and concatenate this with its inverse as a means for a "next best"
>>>>> situation. It seems that this isn't sufficient for my needs and I'm really
>>>>> after creating a continuous 3d gaussian mesh with a "positive" and
>>>>> "negative" dipole.
>>>> The names you're using don't mean anything to me; perhaps there just
>>>> aren't enough atmospheric scientists on the list and that's why you
>>>> didn't get any response.  If you don't get a response this time, you
>>>> should describe what you want in basic terms, and/or point to examples
>>>> of it on the web.
>>>>
>>>> Duncan Murdoch
>>>>
>>>>> Can anyone offer any pointers at all?
>>>>>
>>>>> Laura Quinn
>>>>> Institute of Atmospheric Science
>>>>> School of Earth and Environment
>>>>> University of Leeds
>>>>> Leeds
>>>>> LS2 9JT
>>>>>
>>>>> tel: +44 113 343 1596
>>>>> fax: +44 113 343 6716
>>>>> mail: laura at env.leeds.ac.uk
>>>>>
>>>>> ______________________________________________
>>>>> 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
>>>>
>>




More information about the R-help mailing list