Tuesday, 20 August 2013

R: Manipulating csv scatter data to plot a 3D surface

R: Manipulating csv scatter data to plot a 3D surface

I'm sure this has been asked before. If you can find a good link I'll
happily delete the question but I'm not having any luck with google.
I want to plot some 3D data and searching always leads me back to R
(great/simple alternatives would be welcome).
I have a csv file that looks like this...
x y value
0 0 4.35
0 1 4.23
0 2 4.24
1 0 4.34
1 1 4.23
1 2 4.22
2 0 4.34
2 1 4.22
2 2 4.22
All points in the grid are there and unique, so I don't need any
interpolation.
I can read it like so...
data <- read.table("mydata.csv", header=T, sep=",")
I've found a number of 3d plotting functions: persp, wireframe,
scatterplot3d, rgl/persp3d, rgl/surface. However haven't had any luck
understanding the format they need.
I can output like so...
svg("chart.svg", width=4, height=4)
#plot function call(args??)
dev.off()
What's the shortest way to rearrange and draw my data as a
surface/heightmap and output to SVG (not embedded raster)?

No comments:

Post a Comment