# How to add regression line to the given scatter plot in R?

#1

I am currently trying to plot my regression model in the given scatter plot which I have a plot by using ggplot.I want to know how I can plot my model in the given plot.

``````#### Is the fertility rate of a country was a good predictor of the percentage of the population under 15?
ggplot(WHO, aes(x = FertilityRate, y = Under15)) + geom_point()

####  log transformation:
ggplot(WHO, aes(x = log(FertilityRate), y = Under15)) + geom_point()

#### Simple linear regression model to predict the percentage of the population under 15, using the log of the fertility rate:
mod = lm(Under15 ~ log(FertilityRate), data = WHO)
summary(mod)``````

#2

hello @harry,

There are two ways of achieving this:

``````credit.lm <- lm(Balance ~ Income,data = creditData)
summary(credit.lm)
plot(creditData\$Income,creditData\$Balance)
abline(credit.lm)
``````

This will give:

If you see the plot the intercept is somewhere around 250.If we see the summary(credit.lm):

ggplot2 uses this information:

``````p <- qplot(Income, Balance, data = creditData)
p + geom_abline(intercept = credit.lm\$coefficients[1], slope = credit.lm\$coefficients[2])
``````

to give:

Hope this helps!!