- 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

If we want to create a regression line inside scatterplot then lines function can be used with the linear model function lm but if we want to do it for a particular range of independent variable then this range needs to be defined and passed within the lines function. Check out the below example of linear regression model that considers a range of independent variable for prediction.

Consider the below vectors −

strsplit(x6,"[*]")

Defining the range of x −

Range_of_x <-data.frame(x=1:3)

Adding the regression line for the prediction of range of x values −

lines(Range_of_x$x,predict(lm(y~x),Range_of_x))

- Related Questions & Answers
- How to create a plot with dashed regression line in base R?
- How to create vertical line for X variable at median in base R plot
- How to create horizontal line for Y variable at median in base R plot?
- How to create a horizontal line in a histogram in base R?
- How to perform group-wise linear regression for a data frame in R?
- How to change the order of independent variables for regression summary output in R?
- How to find residual variance of a linear regression model in R?
- How to create a boxplot with log of the variable in base R?
- How to change the line color in a Seaborn linear regression jointplot?
- Create scatterplot for two dependent variables and one independent variable in R.
- How to extract p-values for intercept and independent variables of a general linear model in R?
- How to create a plot of quadratic regression with fitted values against X in base R?
- How to create a list of regression models for predefined vectors in R?
- How to add a regression line to a plot in base R if intercept and slope are given?
- How to find the standardized coefficients of a linear regression model in R?

Advertisements