Functions to Identify and Mark Extreme Points in a 2D Plot.
This function is called by several graphical functions in the 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, method="identify", n = length(x), cex=1, col=carPalette()[1], location=c("lr", "ab", "avoid"), ...)
x |
Plotted horizontal coordinates. |
y |
Plotted vertical coordinates. |
labels |
Plotting labels. When called from within a car plotting function, the labels are automatically obtained from the row names in the data frame used to create the modeling object. If |
method |
How points are to be identified. See Details below. |
n |
Number of points to be identified. If set to 0, no points are identified. |
cex |
Controls the size of the plotted labels. The default is |
col |
Controls the color of the plotted labels. The default is the first element returned by |
location |
Where should the label be drawn? The default is |
... |
not used. |
The argument method
determine how the points
to be identified are selected. For the default value of method="identify"
,
the identify
function is used to identify points
interactively using the mouse. Up to n
points can be identified,
so if 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 method
.
method = "x"
select points according to their value of abs(x - mean(x))
method = "y"
select points according to their value of abs(y - mean(y))
method = "r"
select points according to their value of abs(y)
, as may be
appropriate in residual plots, or others with a meaningful origin at 0
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))
method
can be a vector of the same length as x
consisting of
values to determine the points to be labeled. For example, for a linear model
m
, setting method=cooks.distance(m)
will label the
points corresponding to the largest values of Cook's distance, or
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.
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.
method = "none"
causes no point labels to be shown.
With showLabels
, the method
argument can be a list, so, for
example 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.
A function primarily used for its side-effect of drawing point labels on a plot. Returns invisibly the labels of the selected points, or NULL if no points are selected. Although intended for use with other functions in the car package, this function can be used directly.
John Fox jfox@mcmaster.ca, Sanford Weisberg sandy@umn.edu
Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition, Sage.
plot(income ~ education, Prestige) with(Prestige, showLabels(education, income, labels = rownames(Prestige), method=list("x", "y"), n=3)) m <- lm(income ~ education, Prestige) plot(income ~ education, Prestige) abline(m) with(Prestige, showLabels(education, income, labels=rownames(Prestige), method=abs(residuals(m)), n=4))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.