regplot | R Documentation |
Make a scatter plot of y as a function of x, along with regression line(s).
regplot(
x,
y,
reg = "lm",
col = c(lm = "red"),
show.crit = c("corP", "corS"),
ci.int = TRUE,
pred.int = TRUE,
legend.x = "right",
legend.y = NULL,
las = 1,
...
)
x |
vector or 1-column matrix (missing data coded as NA will be automatically discarded) |
y |
vector or 1-column matrix (missing data coded as NA will be automatically discarded) |
reg |
specifies which model(s) to use to add regression lines(s) (lm/loess/rlm; can be |
col |
named vector specifying the color(s) of the regression line(s) specified via |
show.crit |
specifies which criterion to show in the top left corner (corP/corS/R2adj); can be |
ci.int |
if |
pred.int |
if |
legend.x |
the x coordinate to be used to position the legend (see |
legend.y |
the y coordinate to be used to position the legend (see |
las |
see |
... |
arguments to be passed to |
list of object(s) returned by the function(s) specified via reg
Timothee Flutre
set.seed(1859)
n <- 500
x <- rnorm(n=n, mean=37, sd=3)
y <- 50 + 1.2 * x + rnorm(n=n, mean=0, sd=3)
fit <- regplot(x=x, y=y, reg="lm", las=1, main="Linear regression")
fit <- regplot(x=x, y=y, reg="loess", las=1, col=c(loess="red"),
main="Locally weighted scatterplot smoothing (loess)")
y2 <- y + sample(x=c(rep(0, 0.7*floor(n)),
rnorm(n=ceiling(0.3*n), mean=c(7,13), sd=20)), size=n)
fit <- regplot(x=x, y=y2, reg=c("lm","rlm"), las=1,
col=c(lm="red", rlm="blue"), legend.x="bottomright",
main="(Robust) linear regressions")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.