scatterplot: Scatterplots with Boxplots

Description Usage Arguments Value Author(s) See Also Examples

Description

Makes enhanced scatterplots, with boxplots in the margins, a nonparametric regression smooth, smoothed conditional spread, outlier identification, and a regression line; sp is an abbreviation for scatterplot.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
scatterplot(x, ...)

## S3 method for class 'formula'
scatterplot(formula, data, subset, xlab, ylab, id=FALSE, 
    legend=TRUE, ...)

## Default S3 method:
scatterplot(x, y, smooth=TRUE, id=FALSE, legend=TRUE,
    spread=!by.groups, reg.line=lm,
    boxplots=if (by.groups) "" else "xy",
    xlab=deparse(substitute(x)), ylab=deparse(substitute(y)), las=par("las"),
    lwd=1, lty=1, 
    log="", jitter=list(), xlim=NULL, ylim=NULL,
    cex=par("cex"), cex.axis=par("cex.axis"), cex.lab=par("cex.lab"), 
    cex.main=par("cex.main"), cex.sub=par("cex.sub"), 
    groups, by.groups=!missing(groups), ellipse=FALSE,
    col=if (n.groups == 1) palette()[3:1] else rep(palette(), length=n.groups),
    pch=1:n.groups, 
    reset.par=TRUE, grid=TRUE, ...)

sp(x, ...)

Arguments

x

vector of horizontal coordinates (or first argument of generic function).

y

vector of vertical coordinates.

formula

a “model” formula, of the form y ~ x or (to plot by groups) y ~ x | z, where z evaluates to a factor or other variable dividing the data into groups. If x is a factor, then parallel boxplots are produced using the Boxplot function.

data

data frame within which to evaluate the formula.

subset

expression defining a subset of observations.

smooth

specifies the smoother to be used along with its arguments; if FALSE, no smoother is shown; can be a list giving the smoother function and its named arguments; TRUE, the default, is equivalent to list(smoother=loessLine). See ScatterplotSmoothers for the smoothers supplied by the car package and their arguments.

id

controls point identification; if FALSE (the default), no points are identified; can be a list of named arguments to the showLabels function; TRUE is equivalent to list(method="mahal", n=2, cex=1, col=palette()[1], location="lr"), which identifies the 2 points (in each group) with the largest Mahalanobis distances from the center of the data.

legend

controls placement and properties of a legend if the plot is drawn by groups; if FALSE, the legend is suppressed. Can be a list of named arguments, as follows: title for the legend; inset, giving space (as a proportion of the axes) to offset the legend from the axes; coords specifying the position of the legend in any form acceptable to the legend function or, if not given, the legend is placed above the plot in the upper margin; columns for the legend, determined automatically to prefer a horizontal layout if not given explicitly. TRUE (the default) is equivalent to list(title=deparse(substitute(groups)), inset=0.02).

spread

if TRUE, estimate the (square root) of the variance function. For the loessLine and for gamLine smoothers, this is done by separately smoothing the squares of the postive and negative residuals from the mean fit, and then adding the square root of the fitted values to the mean fit. For quantregLine, the functions shows the .25 and .75 quantiles from a quantile regression additive model. The default is TRUE if by.groups=FALSE and FALSE is by.groups=TRUE.

reg.line

function to draw a regression line on the plot or FALSE not to plot a regression line.

boxplots

if "x" a boxplot for x is drawn below the plot; if "y" a boxplot for y is drawn to the left of the plot; if "xy" both boxplots are drawn; set to "" or FALSE to suppress both boxplots.

xlab

label for horizontal axis.

ylab

label for vertical axis.

las

if 0, ticks labels are drawn parallel to the axis; set to 1 for horizontal labels (see par).

lwd

width of linear-regression lines (default 1).

lty

type of linear-regression lines (default 1, solid line).

log

same as the log argument to plot, to produce log axes.

jitter

a list with elements x or y or both, specifying jitter factors for the horizontal and vertical coordinates of the points in the scatterplot. The jitter function is used to randomly perturb the points; specifying a factor of 1 produces the default jitter. Fitted lines are unaffected by the jitter.

xlim

the x limits (min, max) of the plot; if NULL, determined from the data.

ylim

the y limits (min, max) of the plot; if NULL, determined from the data.

groups

a factor or other variable dividing the data into groups; groups are plotted with different colors and plotting characters.

by.groups

if TRUE, regression lines are fit by groups.

ellipse

controls plotting data-concentration ellipses. If FALSE (the default), no ellipses are plotted. Can be a list of named values giving levels, a vector of one or more bivariate-normal probability-contour levels at which to plot the ellipses; and robust, a logical value determing whether to use the cov.trob function in the MASS package to calculate the center and covariance matrix for the data ellipses. TRUE is equivalent to list(levels=c(.5, .95), robust=TRUE).

col

colors for lines and points; the default is taken from the color palette, with palette()[3] for linear regression lines, palette()[2] for nonparametric regression lines, and palette()[1] for points if there are no groups, and successive colors for the groups if there are groups.

pch

plotting characters for points; default is the plotting characters in order (see par).

cex, cex.axis, cex.lab, cex.main, cex.sub

set sizes of various graphical elements; (see par).

reset.par

if TRUE (the default) then plotting parameters are reset to their previous values when scatterplot exits; if FALSE then the mar and mfcol parameters are altered for the current plotting device. Set to FALSE if you want to add graphical elements (such as lines) to the plot.

grid

If TRUE, the default, a light-gray background grid is put on the graph

...

other arguments passed down and to plot.

Value

If points are identified, their labels are returned; otherwise NULL is returned invisibly.

Author(s)

John Fox jfox@mcmaster.ca

See Also

boxplot, jitter, legend, scatterplotMatrix, dataEllipse, Boxplot, cov.trob, showLabels, ScatterplotSmoothers.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
scatterplot(prestige ~ income, data=Prestige, ellipse=TRUE)

scatterplot(prestige ~ income, data=Prestige, smooth=list(smoother=quantregLine))

scatterplot(prestige ~ income | type, data=Prestige, 
            smooth=list(smoother=loessLine, span=1))

scatterplot(prestige ~ income | type, data=Prestige, legend=list(coords="topleft"))

scatterplot(vocabulary ~ education, jitter=list(x=1, y=1), 
            data=Vocab, smooth=FALSE, lwd=3)

scatterplot(infant.mortality ~ gdp, log="xy", data=UN, id=list(n=5))

scatterplot(income ~ type, data=Prestige)

if(interactive()){ # remember to exit from point-identification mode
    scatterplot(infant.mortality ~ gdp, id=list(method="identify"), data=UN)
}

jonathon-love/car3 documentation built on May 19, 2019, 7:28 p.m.