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.9999
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.9999
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.0000 0 0
V3 8752.9239 4115.487198 1425.49197 166.2719 0.0000 0.0000 0 0
V4 5487.9866 2189.690272 464.96165 0.0000 0.0000 0.0000 0 0
V5 3601.9222 1152.314526 84.35834 0.0000 0.0000 0.0000 0 0
V6 2406.3472 561.860696 0.00000 0.0000 0.0000 0.0000 0 0
V7 1606.2609 229.200968 0.00000 0.0000 0.0000 0.0000 0 0
V8 1054.1819 59.850348 0.00000 0.0000 0.0000 0.0000 0 0
V9 668.1935 1.390629 0.00000 0.0000 0.0000 0.0000 0 0
V10 399.1614 0.000000 0.00000 0.0000 0.0000 0.0000 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.