- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add a regression line to a plot in base R if intercept and slope are given?
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.
Create the vectors and scatterplot
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)
Output
Add regression line with given intercept and slope
Example
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)
Output
- Related Articles
- 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 find the 95% confidence interval for the slope of regression line in R?
- How to add a horizontal line in a boxplot created in base R?
- How to create a vertical line in a time series plot in base R?
- How to create a plot of quadratic regression with fitted values against X in base R?
- How to create a predictive linear regression line for a range of independent variable in base R?
- How to extract odds ratio of intercept and slope coefficient from simple logistic model in R?
- How to plot the regression line starting from origin using ggplot2 in R?
- How to add a horizontal line to the plot created by ggplot2 in R?
- How to assign a value to a base R plot?
- How to add a straight line to a plot in R starting from bottom left and ending at top right?

Advertisements