[R] Contour Plot on a non Rectangular Grid

(Ted Harding) ted.harding at wlandres.net
Sun Oct 24 13:51:05 CEST 2010


On 24-Oct-10 11:30:57, Lorenzo Isella wrote:
> Dear All,
> I would like to plot a scalar (e.g. a temperature) on a non-rectangular
> domain (or even better: I would simply like to be able to draw a
> contour plot on an arbitrary 2D domain). I wonder if there is any
> tool to achieve that with R. I did some online search in particular
> on the list archives, found several queries similar to this one but
> was not able to find any conclusive answer.
> I am interested in the following 2 options
> 
> (1) just read a file of the form
> 
> x1  y1  z1
> x2  y2  x2
> ... ... ...
> xn  yn  zn
> 
> where the set of {xi} and {yi} are coordinates on an arbitrary domain 
> and {zi} are the values of the scalar for the corresponding {x,y} 
> coordinates.
> (2) Sometimes the domain where I want to draw a contour plot is nothing
> too fancy and the scalar itself is given by an analytical function. 
> Consider e.g. the case of a circle of radius R=pi/2 centered about the 
> origin and a function like
> 
> z=f(x,y)=abs(cos(y))
> 
> NB: in this case a satisfactory solution could be to plot z on a 
> rectangular grid and then clip a circular region
> To fix the ideas, the final result in this case (with a colorjet map) 
> should look like this
> 
> http://dl.dropbox.com/u/5685598/scalar_plot.pdf
> 
> Any suggestion is appreciated.
> Many thanks
> 
> Lorenzo

For your option (1), the fundamental issue is interpolation.
There are many methods for this, with different proprties!
An R Site Search on "interpolation" yields a lot of hits.
One (which is fairly basic, but may suit your purposes) is
the interpp() function in package akima:

http://finzi.psych.upenn.edu/R/library/akima/html/interpp.html

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 24-Oct-10                                       Time: 12:51:03
------------------------------ XFMail ------------------------------



More information about the R-help mailing list