[R] Contour Plot on a non Rectangular Grid

Jim Lemon jim at bitwrit.com.au
Mon Oct 25 09:48:59 CEST 2010


On 10/25/2010 03:30 AM, Lorenzo Isella wrote:
>
> Hello,
> I feel I am drowning in a glass of water.
> Consider the following snippet at the end of the email, where I
> generated a set of {x,y,s=f(x,y)} values, i.e. a set of 2D coordinates +
> a scalar on a circle.
> Now, I can get a scatterplot in 3D, but how to get a 2D surface
> plot/levelplot?
> An idea could be to artificially set the z coordinate of the plot as a
> constant (instead of having it equal to s as in the scatterplot) and
> calculate the colormap with the values of s, along the lines of the
> volcano example + surface plot at
>
> http://bit.ly/9MRncd
>
> but I am experiencing problems. However, should I really go through all
> this? There is nothing truly 3D in the plot that I have in mind, you can
> think of it as e.g. some temperature measurement along a tube cross
> section.

Hi Lorenzo,
I'm a bit pressed for time at the moment so I can't write an example, 
but why not just define an empty rectangular plot:

plot(0,xlim=<your xlimits>,ylim=<your ylimits>,type="n",axes=FALSE,
  xlab="",ylab="")

create a matrix of NA values, only calculate the ones that are inside 
your shape and display it in the same way that color2D.matplot(plotrix) 
does? You should get the shape you want with all of the unwanted cells 
blank.

Jim



More information about the R-help mailing list