plotrend: Function for building a scatterplot with a superposing...

View source: R/plotrend.r

plotrendR Documentation

Function for building a scatterplot with a superposing smoothed line

Description

The function creates a scatterplot with a superposing smoothed line as a way to reveal any potential pattern between the variables.

Usage

plotrend(
  x = x,
  y = y,
  col.dots = "black",
  linecol = "blue",
  xlab = NULL,
  ylab = NULL,
  pch.dots = 19,
  xlim = NA,
  ylim = NA,
  cex.dots = 1
)

Arguments

x

A numeric vector representing the X-axis variable.

y

A numeric vector representing the Y-axis variable (response).

col.dots

A string specifying the dot colors. The default value is "black".

linecol

A string specifying the smooth line color. The default is set to "blue".

xlab

(optional) A string specifying X-axis label.

ylab

(optional) A string specifying Y-axis label.

pch.dots

A numeric factor altering the shape of the dots.

xlim

(optional) A numeric vector having the minimum and maximum, respectively for the X-axis variable.

ylim

(optional) A numeric vector having the minimum and maximum, respectively for the Y-axis variable.

cex.dots

A numeric factor altering the size of the dots. The default value is 0.7.

Details

Notice that the smoothed-line is derived from a rather standard algorithm (i.e., loess), implemented in the funcion smoothfit, thus it is only an approximation.

Value

The function returns the above described graph.

Author(s)

Christian Salas-Eljatib

References

  • Salas-Eljatib C. 2021. Análisis de datos con el programa estadístico R: una introducción aplicada. Ediciones Universidad Mayor. Santiago, Chile. 170 p. https://eljatib.com

  • Salas C, Stage AR, and Robinson AP. 2008. Modeling effects of overstory density and competing vegetation on tree height growth. Forest Science 54(1):107-122. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/forestscience/54.1.107")}

Examples

df <- datana::maple
head(df)
m1<-lm(leaf~dbh,data=df)
# Example 1, a residual plot
plotrend(x=df$dbh,y=residuals(m1))
abline(h=0)

datana documentation built on Aug. 18, 2025, 5:18 p.m.