stat_eq | R Documentation |
Add regression equation to 'ggplot',
by using different 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).
stat_eq( x, y, model = "line2P", show.eq = TRUE, xname = "x", yname = "y", yhat = FALSE, eq.x = NULL, eq.y = NULL, text.col = "black", eDigit = 3, eSize = 3 )
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: |
show.eq |
whether to show the regression equation, the value is one of c("TRUE", "FALSE"). |
xname |
to specify the expression of "x" in equation, i.e., expression('x'), see Examples. |
yname |
to specify the expression of "y" in equation, i.e., expression('y'), see Examples. |
yhat |
whether to add a hat symbol (^) on the top of "y" in equation. Default is FALSE. |
eq.x, eq.y |
equation position. |
text.col |
the color used for the equation text. |
eDigit |
the numbers of digits for equation parameters. Default is 3. |
eSize |
font size of equation. Default is 3. |
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).
No return value (called for side effects).
ggtrendline
, stat_rrp
, trendline_sum
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.