Skip to content

question about 3-d plot

4 messages · Deepankar Basu, Andrew, Tony

#
the following should work

library(lattice)
x <- seq(1,100)
y <- seq(1,100)
gr <- expand.grid(x,y)
gr$z <- x + y + rnorm(10000,0,100)
cloud(z ~ x + y, data = gr)

also, look for the package rgl which does similar but with more
possiblities.
On Feb 27, 4:28?pm, Dipankar Basu <basu... at gmail.com> wrote:
#
actually, I just realised you also want a line in the plot.  I am not
super-sure how to do this.
On Feb 27, 5:20?pm, andrew <andrewjohnro... at gmail.com> wrote:
#
Hi Deepankar
The code on the following page looks kind of cool, and also seems to
produce something of the type of graph you are after perhaps:

https://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/rgl/demo/regression.r?rev=702&root=rgl&sortby=date&view=auto

[below is a copy of the code...]


library(rgl)

# demo: regression
# author: Daniel Adler
# $Id$

rgl.demo.regression <- function(n=100,xa=3,za=8,xb=0.02,
                                zb=0.01,xlim=c(0,100),zlim=c(0,100)) {

  rgl.clear("all")
  rgl.bg(sphere = TRUE, color = c("black", "green"), lit = FALSE,
size=2,
                        alpha=0.2, back = "lines")
  rgl.light()
  rgl.bbox()

  x  <- runif(n,min=xlim[1],max=xlim[2])
  z  <- runif(n,min=zlim[1],max=zlim[2])
  ex <- rnorm(n,sd=3)
  ez <- rnorm(n,sd=2)
  esty  <- (xa+xb*x) * (za+zb*z) + ex + ez

  rgl.spheres(x,esty,z,color="gray",radius=1,specular="green",
                texture=system.file("textures/
bump_dust.png",package="rgl"),
                texmipmap=T, texminfilter="linear.mipmap.linear")

  regx  <- seq(xlim[1],xlim[2],len=100)
  regz  <- seq(zlim[1],zlim[2],len=100)
  regy  <- (xa+regx*xb) %*% t(za+regz*zb)

  rgl.surface(regx,regz,regy,color="blue",alpha=0.5,shininess=128)

  lx <- c(xlim[1],xlim[2],xlim[2],xlim[1])
  lz <- c(zlim[1],zlim[1],zlim[2],zlim[2])
  f <- function(x,z) { return ( (xa+x*xb) * t(za+z*zb) ) }
  ly <- f(lx,lz)

  rgl.quads
(lx,ly,lz,color="red",size=5,front="lines",back="lines",lit=F)
}

rgl.open()
rgl.demo.regression()
On Feb 27, 5:28?am, Dipankar Basu <basu... at gmail.com> wrote: