[R] question about 3-d plot

Tony Breyal tony.breyal at googlemail.com
Fri Feb 27 12:28:06 CET 2009


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:
> Hi R Users,
>
> I have produced a simulated scatter plot of y versus x tightly clustered
> around the 45 degree line through the origin with the following code:
>
>  x <- seq(1,100)
>  y <- x+rnorm(100,0,10)
>  plot(x,y,col="blue")
>  abline(0,1)
>
> Is there some way to generate a 3-dimensional analogue of this? Can I get a
> similar simulated scatter plot of points in 3 dimensions where the points
> are clustered around a plane through the origin where the plane in question
> is the 3-dimensional analogue of the 45 degree line through the origin?
>
> Deepankar
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list