Description Usage Arguments Details Value Author(s) See Also Examples
surf3D
plots a surface in 3-D with a color variable.
spheresurf3D
plots a colored image on a sphere.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | surf3D (x, y, z, ..., colvar = z, phi = 40, theta = 40,
col = NULL, NAcol = "white", breaks = NULL,
border = NA, facets = TRUE, colkey = NULL,
panel.first = NULL, clim = NULL, clab = NULL, bty = "n",
lighting = FALSE, shade = NA, ltheta = -135, lphi = 0,
inttype = 1, add = FALSE, plot = TRUE)
spheresurf3D (colvar = matrix(nrow = 50, ncol = 50, data = 1:50, byrow = TRUE),
..., phi = 0, theta = 0,
col = NULL, NAcol = "white", breaks = NULL,
border = NA, facets = TRUE, contour = FALSE,
colkey = NULL, resfac = 1,
panel.first = NULL, clim = NULL, clab = NULL, bty = "n",
lighting = FALSE, shade = NA, ltheta = -135, lphi = 0,
inttype = 1, full = FALSE, add = FALSE, plot = TRUE)
|
x, y, z |
Matrices with x, y and z-values that define the surfaces to
be colored. They should be of the same dimension
as |
colvar |
The variable used for coloring. If a matrix, it should be of the same
dimension as |
theta, phi |
the angles defining the viewing direction.
|
col |
Color palette to be used for coloring the |
NAcol |
Colors to be used for |
breaks |
a set of finite numeric breakpoints for the colors; must have one more breakpoint than color and be in increasing order. Unsorted vectors will be sorted, with a warning. |
border |
The color of the lines drawn around the surface facets.
The default, |
facets |
If |
contour |
If |
colkey |
A logical, The default is to draw the color key on side = 4, i.e. in the right margin.
If |
resfac |
Resolution factor, one value or a vector of two numbers, for
the x and y- values respectively. A value > 1 will increase the
resolution. For instance, if |
panel.first |
A |
clab |
Only if |
clim |
Only if |
bty |
The type of the box, the default is to draw no box.
Set |
lighting |
If not Will overrule See examples in jet.col. |
shade |
the degree of shading of the surface facets. Values of shade close to one yield shading similar to a point light source model and values close to zero produce no shading. Values in the range 0.5 to 0.75 provide an approximation to daylight illumination. See persp. |
ltheta, lphi |
if finite values are specified for |
inttype |
The interpolation type to create the polygons, either
taking the mean of the |
full |
Logical. If |
add |
Logical. If |
plot |
Logical. If |
... |
Additional arguments passed to the plotting methods.
The following persp arguments can be specified:
In addition, the perspbox arguments
|
Function spheresurf3D
is a projection on a sphere with radius 1.
This means that the x- y- and z- axes range from [-1, 1].
Returns the viewing transformation matrix, See trans3D.
Karline Soetaert <karline.soetaert@nioz.nl>
persp for the function on which this implementation is based.
jet.col, plotdev for other examples of surf3D
.
plotdev for zooming, rescaling, rotating a plot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | # save plotting parameters
pm <- par("mfrow")
pmar <- par("mar")
par(mar = c(1, 1, 1, 1))
## =======================================================================
## A three-dimensional shape
## (ala http://docs.enthought.com/mayavi/mayavi/mlab.html)
## =======================================================================
par(mfrow = c(2, 2))
# create grid matrices
X <- seq(0, pi, length.out = 50)
Y <- seq(0, 2*pi, length.out = 50)
M <- mesh(X, Y)
phi <- M$x
theta <- M$y
# x, y and z grids
r <- sin(4*phi)^3 + cos(2*phi)^3 + sin(6*theta)^2 + cos(6*theta)^4
x <- r * sin(phi) * cos(theta)
y <- r * cos(phi)
z <- r * sin(phi) * sin(theta)
# full colored image
surf3D(x, y, z, colvar = y, colkey = FALSE, shade = 0.5,
box = FALSE, theta = 60)
# same, but just facets
surf3D(x, y, z, colvar = y, colkey = FALSE, box = FALSE,
theta = 60, facets = FALSE)
# with colors and border, AND increasing the size
# (by reducing the x- y and z- ranges
surf3D(x, y, z, colvar = y, colkey = FALSE, box = FALSE,
theta = 60, border = "black", xlim = range(x)*0.8,
ylim = range(y)*0.8, zlim = range(z)*0.8)
# Now with one color and shading
surf3D(x, y, z, box = FALSE,
theta = 60, col = "lightblue", shade = 0.9)
## Not run: # rotation
for (angle in seq(0, 360, by = 10))
plotdev(theta = angle)
## End(Not run)
## =======================================================================
## Several other shapes
## http://xahlee.info/surface/gallery.html
## =======================================================================
par(mfrow = c(2, 2))
# Shape 1
M <- mesh(seq(0, 6*pi, length.out = 50),
seq(pi/3, pi, length.out = 50))
u <- M$x ; v <- M$y
x <- u/2 * sin(v) * cos(u)
y <- u/2 * sin(v) * sin(u)
z <- u/2 * cos(v)
surf3D(x, y, z, colvar = z, colkey = FALSE, box = FALSE, phi = 50)
# Shape 2: add border
M <- mesh(seq(0, 2*pi, length.out = 50),
seq(0, 2*pi, length.out = 50))
u <- M$x ; v <- M$y
x <- sin(u)
y <- sin(v)
z <- sin(u + v)
surf3D(x, y, z, colvar = z, border = "black",
colkey = FALSE)
# shape 3: uses same mesh, other perspective (d >1)
x <- (3 + cos(v/2)*sin(u) - sin(v/2)*sin(2*u))*cos(v)
y <- (3 + cos(v/2)*sin(u) - sin(v/2)*sin(2*u))*sin(v)
z <- sin(v/2)*sin(u) + cos(v/2)*sin(2*u)
surf3D(x, y, z, colvar = z, colkey = FALSE, d = 2, facets = FALSE)
# shape 4: more complex colvar
M <- mesh(seq(-13.2, 13.2, length.out = 50),
seq(-37.4, 37.4, length.out = 50))
u <- M$x ; v <- M$y
b <- 0.4; r <- 1 - b^2; w <- sqrt(r)
D <- b*((w*cosh(b*u))^2 + (b*sin(w*v))^2)
x <- -u + (2*r*cosh(b*u)*sinh(b*u)) / D
y <- (2*w*cosh(b*u)*(-(w*cos(v)*cos(w*v)) - sin(v)*sin(w*v))) / D
z <- (2*w*cosh(b*u)*(-(w*sin(v)*cos(w*v)) + cos(v)*sin(w*v))) / D
surf3D(x, y, z, colvar = sqrt(x + 8.3), colkey = FALSE,
theta = 10, border = "black", box = FALSE)
box()
## =======================================================================
## A sphere, with box type with grid lines
## =======================================================================
par(mar = c(2, 2, 2, 2))
par(mfrow = c(1, 1))
M <- mesh(seq(0, 2*pi, length.out = 50),
seq(0, pi, length.out = 50))
u <- M$x ; v <- M$y
x <- cos(u)*sin(v)
y <- sin(u)*sin(v)
z <- cos(v)
colvar <- sin(u*6) * sin(v*6)
surf3D(y, x, z, colvar = colvar, phi = 0, bty = "b2",
lighting = TRUE, ltheta = 40)
## =======================================================================
## Function spheresurf3D
## =======================================================================
par(mfrow = c(2, 2))
spheresurf3D()
# true ranges are [-1, 1]; set limits to [-0.8, 0.8] to make larger plots
lim <- c(-0.8, 0.8)
spheresurf3D(colkey = FALSE, xlim = lim, ylim = lim, zlim = lim)
spheresurf3D(bty = "b", ticktype = "detailed", phi = 50)
spheresurf3D(colvar = matrix(nrow = 30, ncol = 30, data = runif(900)))
## =======================================================================
## Images on a sphere
## =======================================================================
par(mfrow = c(1, 1), mar = c(1, 1, 1, 3))
AA <- Hypsometry$z; AA[AA<=0] <- NA
lim <- c(-0.8, 0.8)
# log transformation of color variable
spheresurf3D(AA, NAcol = "black", theta = 90, phi = 30, box = FALSE,
xlim = lim, ylim = lim, zlim = lim, log = "c")
# restore plotting parameters
par(mfrow = pm)
par(mar = pmar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.