Description Usage Arguments Examples
Plots a regression line from a simple linear model (of the form lm(y ~ x)
) to a plot. Also plots the confidence band for the mean, which is calculated using predict.lm
.
1 2 | add_regres_line(fit, from = NULL, to = NULL, band = TRUE,
ci.col = "#BEBEBEB3", ...)
|
fit |
Object returned by lm. Only models of the form |
from |
Optional (read from fitted model); Draw from this X value. |
to |
Optional (read from fitted model); Draw to this x value. |
band |
Logical. Whether to add a confidence band. |
ci.col |
Colour of the confidence band, if plotted. Defaults to a transparent grey colour. |
... |
Further arguments passed to |
1 2 3 4 5 6 7 8 9 10 11 | #'Add a line across the range of the data from a regression object
with(mtcars, plot(1/wt, mpg, xlim=c(0,0.8), ylim=c(0,40)))
# add_regres_line does not allow I() expressions; yet.
mtcars$inv_wt <- 1 / mtcars$wt
fit <- lm(mpg ~ inv_wt, data=mtcars)
add_regres_line(fit)
# Add the regression line and confidence band behind the data
fit <- lm(height ~ age, data=Loblolly)
with(Loblolly, plot(age, height, pch=19, panel.first=add_regres_line(fit)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.