R: Draw a line with a label, by default its equation
panel.lmlineq
R Documentation
Draw a line with a label, by default its equation
Description
This is an extension of the panel functions panel.abline and
panel.lmline to also draw a label on the line. The
default label is the line equation, and optionally the R squared value
of its fit to the data points.
Usage
panel.ablineq(a = NULL, b = 0,
h = NULL, v = NULL,
reg = NULL, coef = NULL,
pos = if (rotate) 1 else NULL,
offset = 0.5, adj = NULL,
at = 0.5, x, y,
rotate = FALSE, srt = 0,
label = NULL,
varNames = alist(y = y, x = x),
varStyle = "italic",
fontfamily = "serif",
digits = 3,
r.squared = FALSE, sep = ", ", sep.end = "",
col, col.text, col.line,
..., reference = FALSE)
panel.lmlineq(x, y, ...)
Arguments
a, b, h, v, reg, coef
specification of the line.
The simplest usage is to give a and b to describe the
line y = a + b x.
Horizontal or vertical lines can be specified as
arguments h or v, respectively.
The first argument (a) can also be a model object produced by
lm.
See panel.abline for more details.
pos, offset
passed on to panel.text.
For pos: 1 = below, 2 = left, 3 = above, 4 = right,
and the offset (in character widths) is applied.
adj
passed on to panel.text.
c(0,0) = above right, c(1,0) = above left,
c(0,1) = below right, c(1,1) = below left;
offset does not apply when using adj.
fontfamily
passed on to panel.text.
at
position of the equation as a fractional distance along the line.
This should be in the range 0 to 1.
When a vertical line is drawn, this gives the vertical position of
the equation.
x, y
position of the equation in native units. If given, this over-rides
at.
For panel.lmlineq this is the data, passed on as lm(y ~ x).
rotate, srt
set rotate = TRUE to align the equation with the line.
This will over-ride srt, which otherwise gives the rotation
angle.
Note that the calculated angle depends on the current device size;
this will be wrong if you change the device aspect ratio after plotting.
label
the text to draw along with the line. If specified, this will be
used instead of an equation.
varNames
names to display for x and/or y.
This should be a list
like list(y = "Q", x = "X")
or, for mathematical symbols,
alist(y = (alpha + beta), x = sqrt(x[t])).
varStyle
the name of a plotmath function to wrap around the
equation expression, or NULL. E.g. "bolditalic",
"displaystyle".
digits
number of decimal places to show for coefficients in equation.
r.squared
the R^2 statistic to display along with the equation of a line.
This can be given directly as a number, or TRUE, in which
case the function expects a model object (typically
lm) and extracts the R^2 statistic from it.
sep, sep.end
The R^2 (r.squared) value is separated from the
equation by the string sep, and also sep.end is added
to the end. For example:
panel.ablineq(lm(y ~ x), r.squared = TRUE,
sep = " (", sep.end = ")").
..., col, col.text, col.line
passed on to panel.abline and
panel.text.
Note that col applies to both text and line; col.text
applies to the equation only, and col.line applies to line only.
reference
whether to draw the line in a "reference line" style, like that used
for grid lines.
Details
The equation is constructed as an expression using plotmath.