On 2010-04-30 13:35, abotaha wrote:

Dear All,

I want to create a surface plot from the data. My data set is consists of x,
y and z data.
I plotted in very easy way by Excel worksheet as shown in the attached
picture.

I did some steps in R, but I cannot have the same plot as in Excel
worksheet's figure.
the R code is

x<- c(-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1)
y<- c(-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1)
z<- c(0.226598762,   0.132395904,    0.14051906,             0.208607098,    
0.320840304,
0.429423216,    0.54086732,             0.647792527,    0.256692375,
           0.256403273, 0.172881269,    0.121978079,    0.156718831,    
0.17175081,     
0.32791861,             0.420194456,    0.493195109,    0.619020921,
           0.278066455, 0.199822296,    0.140827896,    0.140139205,    
0.206984231,
0.2684947,              0.340728872,    0.422645622,    0.501908648,
           0.285697424, 0.22749307,             0.16881002,             
0.13354722,             0.149532449,
0.213353293,    0.283777474,    0.355946993,    0.427175997,
           0.294521663, 0.236133131,    0.18710497,             0.14828074,     
        0.145457711,
0.182992988,    0.228281887,    0.291865148,    0.341808458,
           0.271987072, 0.252962505,    0.201123092,    0.162942848,    
0.14828074,     
0.167205292,    0.214481881,    0.27141981,             0.332162403,
           0.268966875, 0.253628745,    0.213509108,    0.180342353,    
0.151623426,
0.1617176,              0.192572929,    0.243404723,    0.301780548,
           0.284462825, 0.25473406,             0.215401758,    0.202840815,    
0.171061666,
0.160368388,    0.183680312,    0.226156887,    0.272598273,
           0.305655289, 0.247134344,    0.235118253,    0.214725129,    
0.185684599,
0.167917048,    0.184066896,    0.218763431,    0.256692375)

model<-data.frame(x,y,z)
scatterplot3d(model,  type="h",highlight.3d=TRUE,
col.axis="blue",col.grid="grey", main="scatterplot3d - 2", pch=16,)

Any help would appreciat.

You're misunderstanding what scatterplot3d() does: it produces a
_point cloud_, not a surface. You probably want persp() or
wireframe() in pkg:lattice.

Try this:

 z1 <- matrix(z, 9, 9)
 persp(x, y, z1)

or

 library(lattice)
 g <- expand.grid(x = x, y = y)
 g$z <- z
 wireframe(z ~ x * y, data = g)

or, depending on your needs, you might want to fool around
with persp3d() in the rgl package (assuming that have installed it):

 library(rgl)
 persp3d(x, y, z1, col = 'skyblue')

 -Peter Ehlers




http://n4.nabble.com/forum/FileDownload.jtp?type=n&id=2077409&name=Excel_Figure.png

--
Peter Ehlers
University of Calgary

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

Reply via email to