scatter3d
function uses the rgl
package to draw 3D scatterplots
with various regression surfaces. The function Identify3d
allows you to label points interactively with the mouse:
Press the right mouse button (on a two-button mouse) or the centre button (on a
three-button mouse), drag a
rectangle around the points to be identified, and release the button.
Repeat this procedure for each point or
set of nearby points to be identified. To exit from point-identification mode,
click the right (or centre) button in an empty region of the plot.
scatter3d(x, ...)
"scatter3d"(formula, data, subset, radius, xlab, ylab, zlab, labels, ...)
"scatter3d"(x, y, z,
xlab=deparse(substitute(x)), ylab=deparse(substitute(y)),
zlab=deparse(substitute(z)), axis.scales=TRUE, axis.ticks=FALSE,
revolutions=0, bg.col=c("white", "black"),
axis.col=if (bg.col == "white") c("darkmagenta", "black", "darkcyan")
else c("darkmagenta", "white", "darkcyan"),
surface.col=c("blue", "green", "orange", "magenta", "cyan", "red", "yellow", "gray"), surface.alpha=0.5,
neg.res.col="red", pos.res.col="green",
square.col=if (bg.col == "white") "black" else "gray", point.col="yellow",
text.col=axis.col, grid.col=if (bg.col == "white") "black" else "gray",
fogtype=c("exp2", "linear", "exp", "none"),
residuals=(length(fit) == 1), surface=TRUE, fill=TRUE, grid=TRUE, grid.lines=26, df.smooth=NULL, df.additive=NULL,
sphere.size=1, radius=1, threshold=0.01, speed=1, fov=60,
fit="linear", groups=NULL, parallel=TRUE, ellipsoid=FALSE, level=0.5, ellipsoid.alpha=0.1, id.method=c("mahal", "xz", "y", "xyz", "identify", "none"),
id.n=if (id.method == "identify") Inf else 0,
labels=as.character(seq(along=x)), offset = ((100/length(x))^(1/3)) * 0.02,
model.summary=FALSE, ...)
Identify3d(x, y, z, axis.scales=TRUE, groups = NULL, labels = 1:length(x),
col = c("blue", "green", "orange", "magenta", "cyan", "red", "yellow", "gray"),
offset = ((100/length(x))^(1/3)) * 0.02)
y ~ x + z
or
(to plot by groups) y ~ x + z | g
, where g
evaluates to a factor
or other variable dividing the data into groups.TRUE
, label the values of the ends of the axes.
Note: For Identify3d
to work properly, the value of this argument must
be the same as in scatter3d
.TRUE
, print interior axis-``tick'' labels; the default is FALSE
.
(The code for this option was provided by David Winsemius.)"white"
, "black"
.axis.scales
is FALSE
, then
the second colour is used for all three axes.fit
; for multi-group plots, the colours are used for the regression
surfaces and points in the several groups.0.0
(fully transparent) to 1.0
(opaque); default is 0.5
."exp2"
, "linear"
,
"exp"
, "none".
TRUE
; if residuals="squares"
,
then the squared residuals are shown as squares (using code adapted from Richard
Heiberger). Residuals are available only when there is one surface plotted.TRUE
or FALSE
).TRUE
or FALSE
).TRUE
or FALSE
).NULL
(the default), the gam
function will select the degrees of freedom
for a smoothing spline by generalized cross-validation; if a positive number, a fixed
regression spline will be fit with the specified degrees of freedom.NULL
(the default), the gam
function will select degrees of freedom
for the smoothing splines by generalized cross-validation; if a positive number
or a vector of two positive numbers, fixed
regression splines will be fit with the specified degrees of freedom for each term.formula
method,
that must be the case or the argument may be omitted, in which case spheres are the same size;
for the default
method, the default for the argument, 1
, produces spheres
all of the same size. The radii are scaled so that their median is 1."linear"
, "quadratic"
, "smooth"
,
"additive"
; to display fitted surface(s); partial matching is supported --
e.g., c("lin", "quad")
.NULL
(the default), no groups are defined; if a factor, a different surface
or set of surfaces is plotted for each level of the factor; in this event, the colours in
surface.col
are used successively for the points, surfaces, and residuals corresponding to
each level of the factor.groups
, should the surfaces be constrained to be
parallel? A logical value, with default TRUE
.TRUE
or FALSE
).0.0
(fully transparent) to 1.0
(opaque); default is 0.1
."mahal"
(the default), relatively extreme points are identified automatically
according to their Mahalanobis distances from the centroid (point of means);
if "identify"
, points are identified interactively by right-clicking and dragging a box around them; right-click
in an empty area to exit from interactive-point-identification mode; if "xz"
, identify extreme points in the
predictor plane; if "y"
, identify unusual values of the response; if "xyz"
identify
unusual values of an variable; if "none"
, no point identification.
See showLabels
for more information.0
unless
id.method="identify"
).TRUE
or FALSE
). scatter3d
rescales the three variables
internally to fit in the unit cube; this rescaling will affect regression
coefficients.default
method defaults to
the observation indices, in the formula
method to the row names of the data.surface.col
argument to scatter3d
.scatter3d
does not return a useful value; it is used for its side-effect of
creating a 3D scatterplot. Identify3d
returns the labels of the
identified points.
rgl-package
, gam
if(interactive() && require(rgl) && require(mgcv)){
scatter3d(prestige ~ income + education, data=Duncan)
Sys.sleep(5) # wait 5 seconds
scatter3d(prestige ~ income + education | type, data=Duncan)
Sys.sleep(5)
scatter3d(prestige ~ income + education | type, surface=FALSE,
ellipsoid=TRUE, revolutions=3, data=Duncan)
scatter3d(prestige ~ income + education, fit=c("linear", "additive"),
data=Prestige)
Sys.sleep(5)
scatter3d(prestige ~ income + education | type,
radius=(1 + women)^(1/3), data=Prestige)
}
## Not run:
# # drag right mouse button to identify points, click right button in open area to exit
# scatter3d(prestige ~ income + education, data=Duncan, id.method="identify")
# scatter3d(prestige ~ income + education | type, data=Duncan, id.method="identify")
# ## End(Not run)
Run the code above in your browser using DataCamp Workspace