linefit: Add fit lines to a scatter plot

View source: R/linefit.R

linefitR Documentation

Add fit lines to a scatter plot

Description

Convenient wrapper for stats::lowess(), stats::lm(), and stats::coef(stats::line())

Usage

linefit(
  x,
  y,
  type = "b",
  cex = 4,
  show.lowess = TRUE,
  show.lm = TRUE,
  show.line = TRUE
)

Arguments

x

x values, required

y

y values, required

type

passed through to graphics::lines() for the stats::lowess()

cex

scaling for lowess

show.lowess

Logical value, optional, TRUE by default. Defines if lowess is shown

show.lm

Logical value, optional, TRUE by default. Defines if lm line is shown

show.line

Logical value, optional, TRUE by default. Defines if should show abline(coef(line(x,y)))

Details

This function adds lines to a scatter plot, using lines(stats::lowess()), abline(stats::lm()), and abline(stats::coef()) DOESN'T SEEM TO WORK IF log = 'xy' was used in original plot() NOTE: coef(line()) and lm() give different results

Value

Provides a plot just as a side effect

Examples

## Not run: 
    # see
#?lm  or  ?aov   or  ?glm
# ?line
require(graphics)
plot(cars)
(z <- line(cars))
abline(coef(z))
## Tukey-Anscombe Plot :
plot(residuals(z) ~ fitted(z), main = deparse(z$call))
# ?predict
# ?lowess
# ?scatterplot
#The scatterplot( ) function in the car package offers many enhanced features, including
#fit lines, marginal box plots, conditioning on a factor, and interactive point identification.
#Each of these features is optional.
# Enhanced Scatterplot of MPG vs. Weight
# by Number of Car Cylinders
 library(car)
 scatterplot(mpg ~ wt | cyl, data = mtcars,
             xlab = "Weight of Car", ylab = "Miles Per Gallon",
             main = "Enhanced Scatter Plot",
             labels = row.names(mtcars))

## End(Not run)

ejanalysis/analyze.stuff documentation built on April 2, 2024, 10:10 a.m.