Description Usage Arguments Note Author(s) See Also Examples

`plotrgl`

plots objects created with functions from package `plot3D`

in an rgl window.

1 |

`lighting ` |
Logical, when |

`new ` |
Logical, when |

`add ` |
Logical, when |

`smooth ` |
Logical, specifying whether Gouraud shading (smooth)
or flat shading should be used. See material3d from R-package |

`... ` |
Any argument to the |

Arrows are best reproduced with argument `type`

from the arrows3D
function (package `plot3D`

) set equal to `"cone"`

, although this does
not always work well (there is probably a flaw in how it is implemented).
Another option is to use `type = "triangle"`

, which simply maps the arrows
on the xy-plane, ignoring the z-axis.
In this case, only a view from above (phi = 0) will produce symmetric arrowheads
(when `scale = TRUE`

and `expand = 1`

).

The translation of scatter3D ignores the `pch`

argument but displays
all symbols as squares (if `pch = "."`

) or as filled circles.

The color key is not (cannot be) plotted in rgl.

In `rgl`

, both `lty`

and `lwd`

have to be one number.
For `lwd`

, this has been overruled, i.e. line widths can be a vector.
It is still not possible to use different line types in one type of object.

The actions of the mouse on the plots is to rotate (left), to move (middle), and to zoom it (right).

Karline Soetaert <karline.soetaert@nioz.nl>

material3d, par3d for `rgl`

arguments that can be passed to
the function.

A similar function, plotdev, from package `plot3D`

plots the
3D graphs to the current device (other than a rgl-device).

Any function of package `plot3D`

: see e.g. help files of
persp3D, scatter3D, arrows3D, slice3D, surf3D.

Direct rgl functions, see persp3Drgl, `scatter3Drgl`

, etc....

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 | ```
# save plotting parameters
pm <- par("mfrow")
pmar <- par("mar")
## =======================================================================
## Composite image and contour in 3D
## =======================================================================
# plot reduced resolution (for speed) volcano to traditional window:
VV <- volcano[seq(1, nrow(volcano), by = 3), seq(1, ncol(volcano), by = 3)]
persp3D(z = VV, contour = list(side = "zmax"))
plotrgl(new = TRUE) # new window
# add light, smooth surface change x-axis limits
plotrgl(new = FALSE, lighting = TRUE,
xlim = c(0.2, 0.8), smooth = TRUE)
# same:
# persp3Drgl(z = volcano, contour = list(side = "zmax"),
# lighting = TRUE, xlim = c(0.2, 0.8), smooth = TRUE)
## =======================================================================
## scatters with fitted surface and droplines (see ?scatter3D)
## =======================================================================
par (mfrow = c(1, 1))
with (mtcars, {
# linear regression
fit <- lm(mpg ~ wt + disp)
# predict values on regular xy grid
wt.pred <- seq(1.5, 5.5, length.out = 30)
disp.pred <- seq(71, 472, length.out = 30)
xy <- expand.grid(wt = wt.pred,
disp = disp.pred)
mpg.pred <- matrix (nrow = 30, ncol = 30,
data = predict(fit, newdata = data.frame(xy),
interval = "prediction"))
# fitted points for droplines to surface
fitpoints <- predict(fit)
scatter3D(z = mpg, x = wt, y = disp, pch = 18, cex = 2,
theta = 20, phi = 20, ticktype = "detailed",
xlab = "wt", ylab = "disp", zlab = "mpg",
surf = list(x = wt.pred, y = disp.pred, z = mpg.pred,
facets = NA, fit = fitpoints),
main = "mtcars")
})
plotrgl()
## =======================================================================
## scatter3D with text
## =======================================================================
with(USArrests, text3D(Murder, Assault, Rape,
colvar = UrbanPop, col = gg.col(100), theta = 60, phi = 20,
xlab = "Murder", ylab = "Assault", zlab = "Rape",
main = "USA arrests",
labels = rownames(USArrests), cex = 0.8,
bty = "g", ticktype = "detailed", d = 2,
clab = c("Urban","Pop"), adj = 0.5, font = 2))
with(USArrests, scatter3D(Murder, Assault, Rape - 1,
colvar = UrbanPop, col = gg.col(100),
type = "h", pch = ".", add = TRUE))
plotrgl()
## =======================================================================
## spheresurf3D
## =======================================================================
AA <- Hypsometry$z
# log transformation of color variable; full = TRUE to plot both halves
spheresurf3D(AA, theta = 90, phi = 30, box = FALSE,
full = TRUE, plot = FALSE)
# change the way the left mouse reacts
plotrgl(mouseMode = c("zAxis", "zoom", "fov"))
## =======================================================================
## Arrows - has a flaw
## =======================================================================
z <- seq(0, 2*pi, length.out = 100)
x <- cos(z)
y <- sin(z)
z0 <- z[seq(1, by = 10, length.out = 10)]
z1 <- z[seq(9, by = 10, length.out = 10)]
# cone arrow heads
arrows3D(x0 = 10*cos(z0), y0 = sin(z0), z0 = z0,
x1 = 10*cos(z1), y1 = sin(z1), z1 = z1,
type = "cone", length = 0.4, lwd = 4,
angle = 20, col = 1:10, plot = FALSE)
plotrgl(lighting = TRUE)
## =======================================================================
## 2D plot
## =======================================================================
image2D(z = volcano)
plotrgl()
# reset plotting parameters
par(mfrow = pm)
par(mar = pmar)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.