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. http://n4.nabble.com/forum/FileDownload.jtp?type=n&id=2077409&name=Excel_Figure.png -- View this message in context: http://r.789695.n4.nabble.com/3D-Surface-plot-tp2077409p2077409.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
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
Hi,Sir or Miss: We meet a problem of plotting 3d, which is a part of 5D. In other word, we just fixed the rest of 2 variables and slice 5d into 3d. Consider a function like Y=f(x1, x2, x3, x4). We want to have a 3D surface plot in R for the fitted value Yhat (which is of course a function of x1, x2, x3 and x4) against x1 and x2 say, keeping x3 at its median level and fixing x4 as =1 (note that x4 is binary which can take values of 1 or 0 only). So we plot yhat, x1 and x2 in 3D surface after estimating the whole model (based on all 4 covariates) . Awaiting your reply. Thanks for your time, Best Kun [[alternative HTML version deleted]]
On 11.05.2010 23:25, kun.zhao at wmich.edu wrote:> Hi,Sir or Miss: > > We meet a problem of plotting 3d, which is a part of 5D. In other word, we just fixed the rest of 2 variables and slice 5d into 3d. > > Consider a function like Y=f(x1, x2, x3, x4). We want to have a 3D surface plot in R for the fitted value Yhat (which is of course a function of x1, x2, x3 and x4) against x1 and x2 say, keeping x3 at its median level and fixing x4 as =1 (note that x4 is binary which can take values of 1 or 0 only). So we plot yhat, x1 and x2 in 3D surface after estimating the whole model (based on all 4 covariates) .See ?persp. Uwe Ligges> Awaiting your reply. > Thanks for your time, > Best > Kun > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.