car
package to mark extreme points in a 2D plot. Although the user is unlikely
to call this function directly, the documentation below applies to all
these other functions.showLabels(x, y, labels=NULL, id.method="identify",
id.n = length(x), id.cex=1, id.col=palette()[1], ...)
NULL
, case numbers will be used. If labels are long, the
substr
or abbreviate
function can be used to shorten them.1
.identify
or to text
.id.method
determine how the points
to be identified are selected. For the default value of id.method="identify"
,
the identify
function is used to identify points
interactively using the mouse. Up to id.n
points can be identified,
so if id.n=0
, which is the default in many functions in the car
package, then no point identification is done.
Automatic point identification can be done depending on the value of the
argument id.method
.
id.method = "x"
select points according to their value ofabs(x - mean(x))
id.method = "y"
select points according to their value ofabs(y - mean(y))
id.method = "r"
select points according to their value ofabs(y)
, as may be
appropriate in residual plots, or others with a meaningful origin at 0id.method = "mahal"
Treat(x, y)
as if it were a bivariate sample, and
select cases according to their Mahalanobis distance from(mean(x), mean(y))
id.method
can be a vector of the same length asx
consisting of
values to determine the points to be labeled. For example, for a linear modelm
, settingid.method=cooks.distance(m), id.n=4
will label the
points corresponding to the four largest values of Cook's distance, orid.method = which(abs(residuals(m, type="pearson")) > 2
would label
all observations with Pearson residuals greater than 2 in absolute value.
Warning: If missing data are present, points may be incorrectly labelled.id.method
can be a vector of case numbers or case-labels, in which case
those cases will be labeled. Warning: If missing data are present, a list of
case numbers may identify the wrong points. A list of case labels, however,
will work correctly with missing values.showLabels
, the id.method
argument can be a list, so, for
example id.method=list("x", "y")
would label according to the horizontal
and vertical axes variables.
Finally, if the axes in the graph are logged, the function uses logged-variables
where appropriate.avPlots
, residualPlots
,
crPlots
, leveragePlots
plot(income ~ education, Prestige)
with(Prestige, showLabels(education, income,
labels = rownames(Prestige), id.method=list("x", "y"), id.n=3))
m <- lm(income ~ education, Prestige)
plot(income ~ education, Prestige)
abline(m)
with(Prestige, showLabels(education, income,
labels=rownames(Prestige), id.method=abs(residuals(m)), id.n=4))
Run the code above in your browser using DataLab