The 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 an empty region of the plot.
This is a revision of the Rcmdr
scatter3d
to add the
ability to plot squared residuals.
scatter3dHH(x, y, z,
xlab=deparse(substitute(x)), ylab=deparse(substitute(y)),
zlab=deparse(substitute(z)),
revolutions=0, bg.col=c("white", "black"),
axis.col=if (bg.col == "white") "black" else "white",
surface.col=c("blue", "green", "orange", "magenta",
"cyan", "red", "yellow", "gray"),
neg.res.col="red", pos.res.col="green", 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, grid=TRUE,
grid.lines=26, df.smooth=NULL, df.additive=NULL,
sphere.size=1, threshold=0.01, speed=1, fov=60,
fit="linear", groups=NULL, parallel=TRUE, model.summary=FALSE,
squares = FALSE, square.color = "gray", coef.ratio = 1, ...)
scatter3d
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.
variable for horizontal axis.
variable for vertical axis (response).
variable for out-of-screen axis.
axis labels.
number of full revolutions of the display.
background colour; one of "white"
, "black"
.
colour for axes; default is "white"
for black background,
"black"
for white background.
vector of colours for regression planes,
used in the order specified by fit
.
colours for lines representing negative and positive residuals.
colour of points.
colour of axis labels.
colour of grid lines on the regression surface(s).
type of fog effect; one of "exp2"
, "linear"
,
"exp"
, "none".
plot residuals (TRUE
or FALSE
); available only
when there is one surface plotted.
plot surface(s) (TRUE
or FALSE
).
plot grid lines on the regression surface(s) (TRUE
or FALSE
).
number of lines (default, 26) forming the grid, in each of the x and y directions.
degrees of freedom for the two-dimensional smooth regression surface;
if 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.
degrees of freedom for each explanatory variable in an additive regression;
if 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.
relative sizes of spheres representing points; the actual size is dependent on the number of observations.
if the actual size of the spheres is less than the threshold, points are plotted instead.
relative speed of revolution of the plot.
field of view (in degrees); controls degree of perspective.
one or more of "linear"
, "quadratic"
, "smooth"
,
"additive"
; to display fitted surface(s); partial matching is supported --
e.g., c("lin", "quad")
.
if 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
plane.col
are used successively for the points, surfaces, and residuals corresponding to
each level of the factor.
when plotting surfaces by groups
, should the surfaces be constrained to be
parallel? A logical value, with default TRUE
.
print summary or summaries of the model(s) fit
(TRUE
or FALSE
).
colours for the point labels, given by group. There must be at
least as many colours as groups; if there are no groups, the first colour is used. Normally, the colours
would correspond to the plane.col
argument to scatter3d
.
logical. If TRUE
, the residuals are plotted as
squares.
The sum of the area of the squares is the "residual sum of squares".
If FALSE
, the residuals are plotted as vertical lines.
color for the squares.
number, defaults to 1. Settig coef.ratio
to a number
other than 1 is a primitive way of plotting squared
pseudo-residuals that are not the least-squares residuals. The
reason for displaying non-least-squares residuals is to compare them
to the least-squares residuals and thus get a 3d visual image of
what minimizing the sum of squares actually means.
other arguments are ignored.
John Fox jfox@mcmaster.ca. Squared residuals added by Richard M. Heiberger <rmh@temple.edu>.
rgl.open
, gam
if (FALSE) {
State.x77 <- as.data.frame(state.x77)
with(State.x77, scatter3d(Income, Murder, Illiteracy))
with(State.x77, Identify3d(Income, Murder, Illiteracy, labels=row.names(State.x77)))
with(State.x77, scatter3d(Income, Murder, Illiteracy, fit=c("linear", "quadratic")))
}
Run the code above in your browser using DataLab