1
I would like to know (1) how to obtain the straight line equation and (2) how to insert the line equation and R 2 in my graph generated by ggplot. Researching here, I found similar doubts, but by my inexperience in the R environment I could not modify my script in a way that worked. In the answers I found here, I also got the impression that it is assumed that the equation of the straight line is already known, but I still do not know how to get it. Below is my code, it’s working, but without the straight line equation and the R 2 as I would need.
library(ggplot2)
x <- c(1358, 1464, 1425, 1174, 1296, 1011, 1083, 1206, 1037, 1150, 1092, 1069, 1259, 1225, 1269, 1034, 1221, 1048, 1016, 1129)
y <- c(113, 202, 209, 159, 205, 152, 242, 170, 198, 152, 210, 221, 168, 204, 167, 176, 179, 103, 86, 82)
dados<-data.frame(y, x)
ggplot(dados, aes(x, y)) +
geom_point() +
geom_smooth(method = "lm")
Thanks in advance, all help will be welcome.
This answers your question? How to put the regression equation on a graph?
– Carlos Eduardo Lagosta
I tested it here and it worked. Thank you very much, answered the yes question!
– Roberto