regplot: Scatter plot with regression lines

View source: R/plotting.R

regplotR Documentation

Scatter plot with regression lines

Description

Make a scatter plot of y as a function of x, along with regression line(s).

Usage

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,
  ...
)

Arguments

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 c("lm", "rlm"))

col

named vector specifying the color(s) of the regression line(s) specified via reg

show.crit

specifies which criterion to show in the top left corner (corP/corS/R2adj); can be c("R2adj", "corP")) or NULL

ci.int

if reg="lm", add lines corresponding to confidence intervals

pred.int

if reg="lm", add lines corresponding to prediction intervals

legend.x

the x coordinate to be used to position the legend (see legend)

legend.y

the y coordinate to be used to position the legend (see legend)

las

see par

...

arguments to be passed to plot

Value

list of object(s) returned by the function(s) specified via reg

Author(s)

Timothee Flutre

Examples

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")

timflutre/rutilstimflutre documentation built on Feb. 7, 2024, 8:17 a.m.