On 10/24/2010 01:51 PM, (Ted Harding) wrote:
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.hard...@wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 24-Oct-10                                       Time: 12:51:03
------------------------------ XFMail ------------------------------

Hi,
And thanks for helping. I am anyway a bit puzzled, since case (1) is not only a matter of interpolation. Probably the point I did not make clear (my fault) is that case (1) in my original email does not refer to an irregular grid on a rectangular domain; the set of (x,y) coordinate could stand e.g. a flat metal slab along which I have temperature measurements. The slab could be e.g. elliptical or any other funny shape. What also matters is that the final outcome should not look rectangular, but by eye one should be able to tell the shape of the slab. Case (1) is a generalization of case (2) where I do not have either an analytical expression for the surface not for the scalar.
Cheers

Lorenzo

______________________________________________
R-help@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.

Reply via email to