stat_rrp: Add R square and P-value to 'ggplot'

View source: R/stat_rrp.R

stat_rrpR Documentation

Add R square and P-value to 'ggplot'

Description

Add R-square and P-value of regression models to 'ggplot', by using models built in the 'ggtrendline()' function. The function includes the following models:
"line2P" (formula as: y=a*x+b),
"line3P" (y=a*x^2+b*x+c),
"log2P" (y=a*ln(x)+b),
"exp2P" (y=a*exp(b*x)),
"exp3P" (y=a*exp(b*x)+c),
"power2P" (y=a*x^b),
and "power3P" (y=a*x^b+c).

Usage

stat_rrp(
  x,
  y,
  model = "line2P",
  Pvalue.corrected = TRUE,
  show.Rsquare = TRUE,
  show.pvalue = TRUE,
  Rname = 0,
  Pname = 0,
  rrp.x = NULL,
  rrp.y = NULL,
  text.col = "black",
  eDigit = 3,
  eSize = 3
)

Arguments

x, y

the x and y arguments provide the x and y coordinates for the 'ggplot'. Any reasonable way of defining the coordinates is acceptable.

model

select which model to fit. Default is "line2P". The "model" should be one of c("line2P", "line3P", "log2P", "exp2P", "exp3P", "power2P", "power3P"), their formulas are as follows:
"line2P": y=a*x+b
"line3P": y=a*x^2+b*x+c
"log2P": y=a*ln(x)+b
"exp2P": y=a*exp(b*x)
"exp3P": y=a*exp(b*x)+c
"power2P": y=a*x^b
"power3P": y=a*x^b+c

Pvalue.corrected

if P-value corrected or not, the value is one of c("TRUE", "FALSE").

show.Rsquare

whether to show the R-square, the value is one of c("TRUE", "FALSE").

show.pvalue

whether to show the P-value, the value is one of c("TRUE", "FALSE").

Rname

to specify the character of R-square, the value is one of c(0, 1), corresponding to c(r^2, R^2).

Pname

to specify the character of P-value, the value is one of c(0, 1), corresponding to c(p, P).

rrp.x, rrp.y

the position for R square and P value.

text.col

the color used for the equation text.

eDigit

the numbers of digits for R square and P value. Default is 3.

eSize

font size of R square and P value. Default is 3.

Details

The values of each parameter of regression model can be found by typing trendline_sum function in this package.

The linear models (line2P, line3P, log2P) in this package are estimated by lm function, while the nonlinear models (exp2P, exp3P, power2P, power3P) are estimated by nls function (i.e., least-squares method).

The argument 'Pvalue.corrected' is only valid for non-linear regression.

If "Pvalue.corrected = TRUE", the P-value is calculated by using "Residual Sum of Squares" and "Corrected Total Sum of Squares (i.e. sum((y-mean(y))^2))".

If "Pvalue.corrected = FALSE", the P-value is calculated by using "Residual Sum of Squares" and "Uncorrected Total Sum of Squares (i.e. sum(y^2))".

Value

No return value (called for side effects).

See Also

ggtrendline, stat_eq, trendline_sum


ggtrendline documentation built on April 27, 2022, 9:06 a.m.