📜  如何在 R 中计算回归线 - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:08.510000             🧑  作者: Mango

代码示例1
library(readxl)
  
# import data
Salary_Data <- read_excel("Salary_Data.xls")
  
# plot a scatter plot
plot(Salary_Data$YearsExperience,Salary_Data$Salary,
     main='Regression for YearsExperience and Salary',
     xlab='YearsExperience',ylab='Salary')
  
# plot a regression line
abline(lm(Salary~YearsExperience,data=Salary_Data),col='red')