Description Usage Arguments Value Note Author(s) References See Also Examples
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 in an empty region of the 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 | scatter3d(x, ...)
## S3 method for class 'formula'
scatter3d(formula, data, subset, radius, xlab, ylab, zlab, labels, ...)
## Default S3 method:
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)
|
formula |
“model” formula, of the form |
data |
data frame within which to evaluate the formula. |
subset |
expression defining a subset of observations. |
x |
variable for horizontal axis. |
y |
variable for vertical axis (response). |
z |
variable for out-of-screen axis. |
xlab, ylab, zlab |
axis labels. |
axis.scales |
if |
axis.ticks |
if |
revolutions |
number of full revolutions of the display. |
bg.col |
background colour; one of |
axis.col |
colours for axes; if |
surface.col |
vector of colours for regression planes,
used in the order specified by |
surface.alpha |
transparency of regression surfaces, from |
neg.res.col, pos.res.col |
colours for lines representing negative and positive residuals. |
square.col |
colour to use to plot squared residuals. |
point.col |
colour of points. |
text.col |
colour of axis labels. |
grid.col |
colour of grid lines on the regression surface(s). |
fogtype |
type of fog effect; one of |
residuals |
plot residuals if |
surface |
plot surface(s) ( |
fill |
fill the plotted surface(s) with colour ( |
grid |
plot grid lines on the regression surface(s) ( |
grid.lines |
number of lines (default, 26) forming the grid, in each of the x and z directions. |
df.smooth |
degrees of freedom for the two-dimensional smooth regression surface;
if |
df.additive |
degrees of freedom for each explanatory variable in an additive regression;
if |
sphere.size |
general size of spheres representing points; the actual size is dependent on the number of observations. |
radius |
relative radii of the spheres representing the points. This is normally a vector of the
same length as the variables giving the coordinates of the points, and for the |
threshold |
if the actual size of the spheres is less than the threshold, points are plotted instead. |
speed |
relative speed of revolution of the plot. |
fov |
field of view (in degrees); controls degree of perspective. |
fit |
one or more of |
groups |
if |
parallel |
when plotting surfaces by |
ellipsoid |
plot concentration ellipsoid(s) ( |
level |
expected proportion of bivariate-normal observations included in the concentration ellipsoid(s); default is 0.5. |
ellipsoid.alpha |
transparency of ellipsoids, from |
id.method |
if |
id.n |
Number of relatively extreme points to identify automatically (default, |
model.summary |
print summary or summaries of the model(s) fit
( |
labels |
text labels for the points, one for each point; in the |
col |
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 |
offset |
vertical displacement for point labels (to avoid overplotting the points). |
... |
arguments to be passed down. |
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.
You have to install the rgl
package to produce 3D plots.
John Fox jfox@mcmaster.ca
Fox, J. and Weisberg, S. (2011) An R Companion to Applied Regression, Second Edition, Sage.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.