[R] Contour Plot on a non Rectangular Grid

Lorenzo Isella lorenzo.isella at gmail.com
Sun Oct 24 18:30:48 CEST 2010


>> 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
>
>
> What about the facilities in package rgl then?
>
> Uwe Ligges

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.
Any help is appreciated.
Cheers

Lorenzo



########################################
library(scatterplot3d)
library(rgl)


R <- pi/2

n <- 100

x <- y <- seq(-R,R, length=n)

xys <- c()

temp <- seq(3)

for (i in seq(n)){

for (j in seq(n))

#check I am inside the circle
   if ((sqrt(x[i]^2+y[j]^2))<=R){

temp[1] <- x[i]
temp[2] <- y[j]
temp[3] <- abs(cos(y[j]))
xys <- rbind(xys,temp)

   }


}




scatterplot3d(xys[,1], xys[,2], xys[,3], highlight.3d=TRUE,
  col.axis="blue", col.grid="lightblue",
  main="scatterplot3d - 2", pch=20)



#########################################################



More information about the R-help mailing list