[R] Contour Plot on a non Rectangular Grid

Lorenzo Isella lorenzo.isella at gmail.com
Sun Oct 24 13:30:57 CEST 2010


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



More information about the R-help mailing list