X <- c(2, 5, 7, 8)
Y <- c(1, 2, 3, 3)

linear_regression = lm(Y ~ X)
summary(linear_regression)
## 
## Call:
## lm(formula = Y ~ X)
## 
## Residuals:
##          1          2          3          4 
##  1.804e-16 -7.143e-02  2.143e-01 -1.429e-01 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  0.28571    0.24571   1.163   0.3649  
## X            0.35714    0.04124   8.660   0.0131 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.189 on 2 degrees of freedom
## Multiple R-squared:  0.974,  Adjusted R-squared:  0.961 
## F-statistic:    75 on 1 and 2 DF,  p-value: 0.01307
#linear regression coef
linear_coef <- coef(linear_regression)
print(linear_coef)
## (Intercept)           X 
##   0.2857143   0.3571429
plot(X, Y,
     col = 'red',
     main = 'X vs Y Regression',
     xlim = c(0,10),
     ylim = c(0,10))
abline(linear_regression, col = 'blue')

legend("topleft",
       legend = paste("Slope =", linear_coef[2], "Y_Intercept =", linear_regression[1]))