Created
September 19, 2018 13:51
-
-
Save rohit-gupta/d34db0108fc166b251ffbb80d0821404 to your computer and use it in GitHub Desktop.
Get equation text from a R lm (Linear Model) object for use as text in graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get equation text from LM | |
# Format: y = a + b.x, R^2 = r^2 | |
equation_text = function(x, round_dig = 2) { | |
lm_coef <- list(a = as.character(round(coef(x)[1], digits = round_dig)), | |
b = as.character(round(coef(x)[2], digits = round_dig)), | |
r2 = round(summary(x)$r.squared, digits = round_dig)); | |
lm_eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(R)^2~"="~r2,lm_coef) | |
as.character(as.expression(lm_eq)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment