[R] Plot a sphere
Derick Schoonbee
schoonbee at hotmail.com
Fri Dec 26 13:02:04 CET 2003
Uwe,
Thanks, I installed it and ran:
rgl.spheres(rnorm(10),rnorm(10),rnorm(10),radius=1,color=rainbow(10))
Nice :)
Thus, I'll give rgl a try but still would be 'stuborn' to see if I can
figure a way out to use persp.
Regards,
D.
From: Uwe Ligges <ligges at statistik.uni-dortmund.de>
To: Spencer Graves <spencer.graves at pdf.com>
CC: Derick Schoonbee <schoonbee at hotmail.com>,r-help at stat.math.ethz.ch
Subject: Re: [R] Plot a sphere
Date: Fri, 26 Dec 2003 12:48:49 +0100
Spencer Graves wrote:
>
> A hemisphere is relatively easy; try the following:
>
> x <- seq(-1, 1, length=21)
> Z <- outer(x, x, function(x, y)sqrt(1-x^2-y^2))
> persp(x=x, y=x, z=Z)
>
> A contour plot is also relatively easy:
>
> image(x=x, y=x, z=Z)
> contour(x=x, y=x, z=Z, add=T)
>
> However, if you want an honest perspective plot of a sphere
> complete with the underside, etc., I know of nothing in R that could do
> that. S-Plus has "perspp", which could be used. However, that seems to
> be one of the few features available in S-Plus that is not currently
> available in R.
The R package "rgl" by Adler and Nenadic can plot spheres. It is
available at
http://wsopuppenkiste.wiso.uni-goettingen.de/~dadler/rgl/
--- and looks like it will shortly become a CRAN package.
Uwe Ligges
> hope this helps.
> spencer graves
>
> Derick Schoonbee wrote:
>
> > Hi,
> >
> > I'm new to R (and math ;) Would somebody please be so kind as to
> > direct me in plotting a 3D sphere?
> >
> > I tried something in the lines of:
> > ####
> > y <- x <- seq(-pi, pi, length=pi*10)
> > f <- function(x,y)
> > {
> > z <- sqrt(pi - x^2 - y^2)
> > #z[is.na(z)] <- 0
> > z
> > }
> > z <- outer(x, y, f)
> >
> > persp(x, y, z, theta = 120, phi = 30)
> > ####
> >
> > I've also tried: .... make.surface.grid(...) .. persp( as.surface(
> > grid, z) ) ... with the same result: 'Incomplete' demi sphere and
> > others..
> >
> > Any suggestions/solutions would be appreaciated.
> >
> > Regards,
> > Derick
> >
> > PS:Merry X-mas ;)
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list