Re: [R] How to create surface3d plot with surface data

2013-05-21 Thread nguyen.hoang
WIth x, y are vectors, the grid is plotted by surface3d.  Thanks for your
answer.

My code is here;
#SurfacePlot is plotted by above surface data
Surface - read.csv(D:/R/Surface.csv, header=F)
Surface - as.matrix(Surface)
x - Surface[2:17,1] 
x - as.numeric(x) # x is vector 1x16
y - Surface[1,2:11]
y - t(y)
y - as.numeric(y) #y is vector 1x10
z - Surface[2:17,2:11] # z is matrix 16x10

plot3d(ScatterPlot$x1, ScatterPlot$y1, ScatterPlot$z1,
xlab=x,ylab=y,zlab=z, type=s, col = blue, size=0.25, lit=FALSE)   
 
# ScatterPlot is showed as below data.
surface3d(x,y,z,alpha=0.4,front=lines,back=lines)

I combined surface3d and plot3d() in graph. 

And now, I want to add line segments showing the error between points of
scatter plot and grid of surface3d. 

ScatterPlot Data:

X1   Y1 Z1  
1   25000.030   0.001218202 0.1915856   
2   5118.15450  0.061169029 0.4711610   
3   17005.82875 0.007177435 0.3222662   
4   5300.22698  0.029688212 0.2770485
...
(3000 points)

I think I should build linear model to predict z1_new values from x1  y1
based on Surface data, And use spheres3d() to plot points of Scatterplot on
surface grid, and then use segment3d() to add line segments  between points
of scatter plot and grid of surface3d coordinate. 

But. i don't know to do that. What should I do? my method is true ?

Nguyen.Hoang




--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-create-surface3d-plot-with-surface-data-tp4667483p4667555.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] How to create surface3d plot with surface data

2013-05-20 Thread Duncan Murdoch

On 13-05-20 12:17 AM, Nguyen Hoang wrote:

I'm very new to R, and I'm having trouble figuring out a 3d surface
plot of the data. I typically have something like this:






   0.1
   0.2
   0.3
   0.4
   0.5


   0.001
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0025
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0039
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0061
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0095
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0147
   40960.16
   40960.16
   40960.16
   33756.49
   25979.93


   0.023
   40960.16
   40960.16
   28130.81
   19838.51
   14891.95


   0.0358
   40960.16
   26877.74
   16258.07
   11004.66
   7898.252


   0.0558
   35941.34
   15461.96
   8752.924
   5487.987
   3601.922


   0.087
   21231.18
   8254.491
   4115.487
   2189.69
   1152.315


   0.1357
   11883.95
   3815.37
   1425.492
   464.9616
   84.35834


   0.2115
   6029.579
   1264.774
   166.2719
   0
   0


   0.3296
   2500.958
   115.8725
   0
   0
   0


   0.5138
   605.4039
   0
   0
   0
   0


   0.801
   0
   0
   0
   0
   0


   0.
   0
   0
   0
   0
   0

a first row corresponding to the values in y and a first column
corresponding to the values in x,the matrix of residual values are in
z as the following:



x1 - t(x) #transpose x

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
V1  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9 1

y1 - t(y)

   [,1]
V1  0.0010
V2  0.0010
V3  0.0039
V4  0.0061
V5  0.0095
V6  0.0147
V7  0.0230
V8  0.0358
V9  0.0558
V10 0.0870
V11 0.1357
V12 0.2115
V13 0.3296
V14 0.5138
V15 0.8010
V16 0.



z_t - t(z)

 [,1] [,2] [,3] [,4] [,5] [,6]  [,7]  [,8]
V1  40960.16 40960.16 40960.16 40960.16 40960.16 40960.16 40960.165 40960.165
V2  40960.16 40960.16 40960.16 40960.16 40960.16 40960.16 40960.165 26877.741
V3  40960.16 40960.16 40960.16 40960.16 40960.16 40960.16 28130.814 16258.071
V4  40960.16 40960.16 40960.16 40960.16 40960.16 33756.49 19838.507 11004.663
V5  40960.16 40960.16 40960.16 40960.16 40960.16 25979.93 14891.946  7898.252
V6  40960.16 40960.16 40960.16 40960.16 35282.13 20810.88 11618.426  5865.759
V7  40960.16 40960.16 40960.16 40960.16 29505.17 17131.90  9301.074  4447.296
V8  40960.16 40960.16 40960.16 40960.16 25179.81 14384.26  7581.456  3412.924
V9  40960.16 40960.16 40960.16 36868.08 21822.20 12257.56  6260.442  2634.903
V10 40960.16 40960.16 40960.16 32663.23 19142.03 10565.56  5218.556  2036.595
   [,9][,10]   [,11] [,12] [,13][,14] [,15] 
[,16]
V1  35941.3351 21231.183500 11883.95464 6029.5794 2500.9576 605.4039 0 0
V2  15461.9567  8254.491283  3815.37041 1264.7739  115.8725   0. 0 0
V3   8752.9239  4115.487198  1425.49197  166.27190.   0. 0 0
V4   5487.9866  2189.690272   464.961650.0.   0. 0 0
V5   3601.9222  1152.31452684.358340.0.   0. 0 0
V6   2406.3472   561.860696 0.00.0.   0. 0 0
V7   1606.2609   229.200968 0.00.0.   0. 0 0
V8   1054.181959.850348 0.00.0.   0. 0 0
V9668.1935 1.390629 0.00.0.   0. 0 0
V10   399.1614 0.00 0.00.0.   0. 0 0


I tried to use surface3d() and persp3d(), but the results was error.



library(rgl)
surface3d(x1,y1,z_t)

Error in rgl.surface(x = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9,  :
   bad dimension for rows


What should I do?


Don't convert x and y into matrices, leave them as vectors.

Unlike persp, persp3d allows you to specify x and/or y as matrices, but 
then they need to be the same shape as z. It was complaining because it 
thought you had done that, but got the shape wrong.


Duncan Murdoch

__
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.