plotLine {fastGraph} | R Documentation |
X-Y Plotting with Simple Linear Regression Line and Equation
Description
The function plots a simple scatter plot, fits the regression line on the scatter plot, and lists the equation of the fitted regression line as the title.
Usage
plotLine(x, y = NULL, data = NULL, xlab = NULL, ylab = NULL, pch = 19,
col = c("black", "red"), digits.intercept = NULL, digits.slope = NULL, ...)
Arguments
x |
The x coordinates of points in the plot. Alternatively, a single plotting structure or function can be provided. |
y |
The y coordinates of points in the plot, optional if |
data |
A data frame including the |
xlab |
The label of the |
ylab |
The label of the |
pch |
The plotting character; i.e., symbol to use. This can be either a single character or an integer code for one of a set of graphics symbols. |
col |
A vector of size two for the color code or name. The first value is the color of the plotting character, and the second value is the color of the fitted regression line. |
digits.intercept |
The desired number of significant digits for the intercept. |
digits.slope |
The desired number of significant digits for the slope. |
... |
Optional arguments to be passed to the |
Note
This function plotLine
uses functions plot
and lm
.
Author(s)
Steven T. Garren, James Madison University, Harrisonburg, Virginia, USA
See Also
Examples
par( mfrow=c(2,2) )
x = c( 2, 6, 5, -3, 11, 3 ) ; y = c( 16, 12, 19, -13, 27, 5 )
plotLine( x, y )
plotLine( x, -y, col=c("red", "green"), digits.intercept=2, digits.slope=3 )
d = data.frame( x=c( 2, 7, 9, 15, 12 ), y=c( 45, 32, 22, 15, 19 ) )
plotLine( y~x, data=d, col=c("blue","orange") )
plotLine( y~x, data=d, xlab="TIME", ylab="EXPENSE", digits.intercept=3, digits.slope=4 )
par( mfrow=c(1,1) )