# Trendline formula in R [closed]

I have created a simple scatterplot to analyse the correlation between two variables, x and y. Using the abline command, I added a trendline to this data. I now want to know the formula for this trendline. Is there a command that will give this formula as one is able to do in a simple Excel scatterplot?

-
Welcome to the site, @Kait. Note that purely R questions belong on Stack Overflow, whereas CV is for questions about the statistical content. We will migrate your Q over there for you in time(please don't cross-post SE strongly discourages this), but 1st we should help you formulate it (here are a couple of relevant discussions: how-to-ask-question-related-to-the-use-of-r, & how-to-make-a-great-r-reproducible-example). Can you paste your code into your Q? – gung Oct 11 '12 at 3:37
I for one provided an example on how to display regression equation in a scatter plot on Stack Overflow. There are plenty of other related threads, IMO, and SO is better suited for such questions. – chl Oct 11 '12 at 10:35

## closed as off topic by chl♦Oct 11 '12 at 10:35

Questions on Cross Validated are expected to relate to statistics within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

This should get you going.

x <- sample(1:100, 100, replace = TRUE)
y <- x + rnorm(100, sd = 4)
mydf <- data.frame(x = x, y = y)
plot(y ~ x, data = mydf)
model <- lm(y ~ x, data = mydf)
abline(model, col = "red")
summary(model)
coef(model)


-

Search for lm command and you can get linear model formula from it.

-