scatterplot

0th

Percentile

Scatterplots with Boxplots

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

Keywords
hplot
Usage
scatterplot(x, ...)

## S3 method for class 'formula':
scatterplot(x, data, subset, xlab, ylab, legend.title, legend.coords,
	labels, ...)

## S3 method for class 'default':
scatterplot(x, y, smooth=TRUE, spread=!by.groups, 
	span=.5, loess.threshold=5, reg.line=lm, 
	boxplots=if (by.groups) "" else "xy",
	xlab=deparse(substitute(x)), ylab=deparse(substitute(y)), 
	las=par("las"), lwd=1, lwd.smooth=lwd, lwd.spread=lwd, lty=1, 
	lty.smooth=lty, lty.spread=2,
	labels, id.method = "mahal", 
	id.n = if(id.method[1]=="identify") length(x) else 0, 
	id.cex = 1, id.col = palette()[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), 
	legend.title=deparse(substitute(groups)), legend.coords,
	ellipse=FALSE, levels=c(.5, .95), robust=TRUE,
	col=if (n.groups == 1) palette()[3:1] else rep(palette(), 
		length=n.groups),
	pch=1:n.groups, 
	legend.plot=!missing(groups), reset.par=TRUE, grid=TRUE, ...)
  
sp(...)
Arguments
x
vector of horizontal coordinates, or 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
y
vector of vertical coordinates.
data
data frame within which to evaluate the formula.
subset
expression defining a subset of observations.
smooth
if TRUE (the default) a loess nonparametric regression line is drawn on the plot.
spread
if TRUE (the default when there are no groups), a smoother is applied to the root-mean-square positive and negative residuals from the loess line to display conditional spread and asymmetry.
span
span for the loess smoother.
loess.threshold
suppress the loess smoother if there are fewer than loess.threshold unique values (default, 5) of y.
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
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).
lwd.smooth
width for smooth regression lines (default is the same as lwd).
lwd.spread
width for lines showing spread (default is the same as lwd).
lty
type of linear-regression lines (default 1, solid line).
lty.smooth
type of smooth regression lines (default is the same as lty).
lty.spread
width for lines showing spread (default is 2, broken line).
id.method,id.n,id.cex,id.col
Arguments for the labelling of points. The default is id.n=0 for labeling no points. See showLabels for details of these arguments. If the plot uses different colors for gr
labels
a vector of point labels; if absent, the function tries to determine reasonable labels, and, failing that, will use observation numbers.
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 us
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.
legend.title
title for legend box; defaults to the name of the groups variable.
legend.coords
coordinates for placing legend; an be a list with components x and y to specify the coordinates of the upper-left-hand corner of the legend; or a quoted keyword, such as "topleft", recognized by le
ellipse
if TRUE data-concentration ellipses are plotted.
levels
level or levels at which concentration ellipses are plotted; the default is c(.5, .95).
robust
if TRUE (the default) use the cov.trob function in the MASS package to calculate the center and covariance matrix for the data ellipses.
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
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).
legend.plot
if TRUE then a legend for the groups is plotted in the upper margin.
reset.par
if TRUE 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.
...
other arguments passed down and to plot.
grid
If TRUE, the default, a light-gray background grid is put on the graph
Value

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

See Also

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

Aliases
  • scatterplot
  • scatterplot.formula
  • scatterplot.default
  • sp
Examples
scatterplot(prestige ~ income, data=Prestige, ellipse=TRUE)

scatterplot(prestige ~ income|type, data=Prestige, span=1)

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

scatterplot(vocabulary ~ education, jitter=list(x=1, y=1), 
	data=Vocab, id.n=0, smooth=FALSE)

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

scatterplot(income ~ type, data=Prestige)

	scatterplot(infant.mortality ~ gdp, id.method="identify", data=UN)
Documentation reproduced from package car, version 2.0-11, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.