- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 plot the regression line starting from origin using ggplot2 in R?
The regression line starting from origin means that the intercept of the model is dropped from the regression model. To plot the regression line starting from origin, we can use the formula by subtracting 1 in geom_smooth function of ggplot2 package.
Consider the below data frame −
x<-rnorm(20) y<-rnorm(20) df<-data.frame(x,y) df
x y 1 0.7936844 1.18542740 2 -0.6143234 -0.06681784 3 -0.5260676 0.26993531 4 -0.9181893 -0.03549873 5 -0.2728913 -1.03655161 6 -0.7030962 1.18929567 7 -0.6145780 0.61194367 8 -2.7765935 -0.06167213 9 -2.2535913 0.59793773 10 -0.7330266 -1.07433426 11 0.6723913 1.25331326 12 1.6307157 0.09585268 13 -0.4791150 -1.01449433 14 -0.9577056 0.80677202 15 0.1023982 0.79843355 16 -1.0203498 -0.35537811 17 -0.9433246 -0.80303154 18 0.6654104 0.73242246 19 -1.2954933 2.46313259 20 0.4077880 0.23019373
Loading ggplot2 package and creating regression line for the linear regression model between x and y −
library(ggplot2) ggplot(df,aes(x,y))+geom_point()+geom_smooth(method=lm,se=FALSE) `geom_smooth()` using formula 'y ~ x'
Creating regression line starting from origin for the linear regression model between x and y −
- How to limit the length of regression line using ggplot2 in R?
- How to plot the confidence interval of the regression model using ggplot2 with transparency in R?
- How to display regression slope using model in a plot created by ggplot2 in R?
- How to display regression intercept using model in a plot created by ggplot2 in R?
- Create multiple regression lines in a single plot using ggplot2 in R.
- How to create quantile regression plot with larger width of lines using ggplot2 in R?
- How to create regression model line in a scatterplot created by using ggplot2 in R?
- How to create multiple regression lines using ggplot2 in R?
- How to display a line in segment of a plot using ggplot2 in R?
- How to create a plot with dashed regression line in base R?
- How to put the plot title inside the plot using ggplot2 in R?
- How to add a horizontal line to the plot created by ggplot2 in R?
- How to write plot description outside plot in facetted plot using ggplot2 in R?
- How to change the partial plot background using ggplot2 in R?
- How to create a scatterplot with regression line using ggplot2 with 0 intercept and slope equals to 1 in R?