These functions draw ellipses, including data ellipses, and confidence ellipses for linear, generalized linear, and possibly other models.
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  ellipse(center, shape, radius, log="", center.pch=19, center.cex=1.5,
segments=51, draw=TRUE, add=draw, xlab="", ylab="",
col=palette()[2], lwd=2, fill=FALSE, fill.alpha=0.3, grid=TRUE, ...)
dataEllipse(x, y, groups, group.labels = group.levels, ellipse.label,
weights, log = "", levels = c(0.5, 0.95), center.pch = 19,
center.cex = 1.5, draw = TRUE, plot.points = draw, add = !plot.points,
segments = 51, robust = FALSE, xlab = deparse(substitute(x)),
ylab = deparse(substitute(y)),
col = if (missing(groups)) palette()[1:2] else palette()[1:length(group.levels)],
pch = if (missing(groups)) 1 else seq(group.levels), lwd = 2,
fill = FALSE, fill.alpha = 0.3, grid = TRUE, labels, id.method = "mahal",
id.n = if (id.method[1] == "identify") Inf else 0, id.cex = 1,
id.col = if (missing(groups)) palette()[1] else palette()(1:length(groups)),
id.location="lr", ...)
confidenceEllipse(model, ...)
## S3 method for class 'lm'
confidenceEllipse(model, which.coef, L, levels=0.95, Scheffe=FALSE, dfn,
center.pch=19, center.cex=1.5, segments=51, xlab, ylab,
col=palette()[2], lwd=2, fill=FALSE, fill.alpha=0.3, draw=TRUE, add=!draw, ...)
## S3 method for class 'glm'
confidenceEllipse(model, chisq, ...)
## Default S3 method:
confidenceEllipse(model, which.coef, L, levels=0.95, Scheffe=FALSE, dfn,
center.pch=19, center.cex=1.5, segments=51, xlab, ylab,
col=palette()[2], lwd=2, fill=FALSE, fill.alpha=0.3, draw=TRUE, add=!draw, ...)

center 
2element vector with coordinates of center of ellipse. 
shape 
2 * 2 shape (or covariance) matrix. 
radius 
radius of circle generating the ellipse. 
log 
when an ellipse is to be added to an existing plot, indicates
whether computations were on logged values and to be plotted on logged
axes; 
center.pch 
character for plotting ellipse center; if 
center.cex 
relative size of character for plotting ellipse center. 
segments 
number of linesegments used to draw ellipse. 
draw 
if 
add 
if 
xlab 
label for horizontal axis. 
ylab 
label for vertical axis. 
x 
a numeric vector, or (if 
y 
a numeric vector, of the same length as 
groups 
optional: a factor to divide the data into groups; a separate ellipse will be plotted for each group (level of the factor). 
group.labels 
labels to be plotted for the groups; by default, the levels of the 
ellipse.label 
a label for the ellipse(s) or a vector of labels; if several ellipses are drawn and just one label is given, then that label will be repeated. The default is not to label the ellipses. 
weights 
a numeric vector of weights, of the same length as 
plot.points 
if 
levels 
draw elliptical contours at these (normal) probability or confidence levels. 
robust 
if 
model 
a model object produced by 
which.coef 
2element vector giving indices of coefficients to plot; if missing, the first two coefficients (disregarding the regression constant) will be selected. 
L 
As an alternative to selecting coefficients to plot, a transformation matrix can be specified to compute two
linear combinations of the coefficients; if the 
Scheffe 
if 
dfn 
“numerator” degrees of freedom (or just degrees of freedom for a GLM) for
drawing the confidence ellipse. Defaults to the number of coefficients in the model (disregarding the constant) if

chisq 
if 
col 
color for lines and ellipse center; the default is the second entry
in the current color palette (see 
pch 
for 
lwd 
line width; default is 
fill 
fill the ellipse with translucent color 
fill.alpha 
transparency of fill (default = 
... 
other plotting parameters to be passed to 
labels,id.method,id.n,id.cex,id.col,id.location 
Arguments for the labelling of
points. The default is 
grid 
If TRUE, the default, a lightgray background grid is put on the graph 
The ellipse is computed by suitably transforming a unit circle.
dataEllipse
superimposes the normalprobability contours over a scatterplot
of the data.
These functions are mainly used for their side effect of producing plots. For
greater flexibility (e.g., adding plot annotations), however, ellipse
returns invisibly the (x, y) coordinates of the calculated ellipse.
dataEllipse
and confidenceEllipse
return invisibly the coordinates of one or more ellipses, in the latter instance a list named by
levels
.
Georges Monette, John Fox jfox@mcmaster.ca, and Michael Friendly.
Fox, J. (2008) Applied Regression Analysis and Generalized Linear Models, Second Edition. Sage.
Fox, J. and Weisberg, S. (2011) An R Companion to Applied Regression, Second Edition, Sage.
Monette, G. (1990) Geometry of multiple regression and 3D graphics. In Fox, J. and Long, J. S. (Eds.) Modern Methods of Data Analysis. Sage.
cov.trob
, cov.wt
, linearHypothesis
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  dataEllipse(Duncan$income, Duncan$education, levels=0.1*1:9,
ellipse.label=0.1*1:9, lty=2, fill=TRUE, fill.alpha=0.1)
confidenceEllipse(lm(prestige~income+education, data=Duncan), Scheffe=TRUE)
confidenceEllipse(lm(prestige~income+education, data=Duncan),
L=c("income + education", "income  education"))
wts < rep(1, nrow(Duncan))
wts[c(6, 16)] < 0 # delete Minister, Conductor
with(Duncan, {
dataEllipse(income, prestige, levels=0.68)
dataEllipse(income, prestige, levels=0.68, robust=TRUE, plot.points=FALSE, col="green3")
dataEllipse(income, prestige, weights=wts, levels=0.68, plot.points=FALSE, col="brown")
dataEllipse(income, prestige, weights=wts, robust=TRUE, levels=0.68,
plot.points=FALSE, col="blue")
})
with(Prestige, dataEllipse(income, education, type, id.n=2, pch=15:17,
labels=rownames(Prestige), xlim=c(0, 25000), center.pch="+",
group.labels=c("Blue Collar", "Professional", "White Collar"),
ylim=c(5, 20), level=.95, fill=TRUE, fill.alpha=0.1))

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.