- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

To add a regression line to a plot in base R if intercept and slope are given, we can follow the below steps −

- First of all, create two vectors and the scatterplot between them.
- Then, use abline function to create the regression line with intercept and slope given by a and b respectively.

Use plot functions to create scatterplot between two random vectors x and y −

> x<-round(rnorm(20),2) > y<-round(rnorm(20),2) > plot(x,y)

Using abline function to add the regression line to the scatterplot with given intercept a = 0.51 and slope = -1.05 −

> x<-round(rnorm(20),2) > y<-round(rnorm(20),2) > plot(x,y) > abline(a=0.51,b=-1.05)

- Related Questions & Answers
- How to create a scatterplot with regression line using ggplot2 with 0 intercept and slope equals to 1 in R?
- How to create a plot with dashed regression line in base R?
- How to display regression intercept using model in a plot created by ggplot2 in R?
- How to display regression slope using model in a plot created by ggplot2 in R?
- How to add a picture to plot in base R?
- How to add a horizontal line in a boxplot created in base R?
- How to find the 95% confidence interval for the slope of regression line in R?
- How to create a predictive linear regression line for a range of independent variable in base R?
- How to create a vertical line in a time series plot in base R?\n
- How to extract odds ratio of intercept and slope coefficient from simple logistic model in R?
- How to create a plot of quadratic regression with fitted values against X in base R?
- How to assign a value to a base R plot?
- How to add a horizontal line to the plot created by ggplot2 in R?
- How to plot the regression line starting from origin using ggplot2 in R?
- How to create a plot in base R without margins?

Advertisements