Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple R 3d interpolation / surface plot

Tags:

r

I know this has been addressed many times, but i just cant seem to get my head around it. Hopefully someone can explain in a little more detail the steps i need to go through to achieve a surface plot in R.

I have a set of [x,y,z] points that i would like to turn into a surface plot. From reading around i can see that i will need to interpolate with Kring or something of the sort. I have absolutely no experience with 3d interpolation, so if someone could add how i would interpolate from a set of points in 3d space that would be a huge help.

Once i have that data set, i would like to create a surface plot from it. From what i understand i can use the interp() function to do so, but again i am not quite sure how.

If there is another post which you think has already answered this question, please direct me towards it.

thanks in advance!

like image 316
user1003131 Avatar asked Dec 14 '11 16:12

user1003131


1 Answers

Use the akima package. It has an interp function that's pretty straightforward.

library(akima)

x <- rnorm(20)
y <- rnorm(20)
z <- rnorm(20)

s <- interp(x,y,z)

Once you have the interpolated matrix you can do a variety of things.

One example is the image.plot function in the fields package.

image.plot(s)
like image 176
screechOwl Avatar answered Sep 23 '22 15:09

screechOwl