Given data as follow.
#To know current directory.
getwd()
## [1] "C:/Users/Gio/Documents/How to Fit a Linear Curve to Data in R"
#Set to the current directory
setwd("C:/Users/Gio/Documents/How to Fit a Linear Curve to Data in R")
#read or open data "data2.csv" in R
data=read.csv("data2.csv")
#Show the data
data
## Income Expenditure
## 1 1000000 700000
## 2 2000000 1500000
## 3 3000000 2300000
## 4 4000000 2700000
## 5 5000000 2500000
## 6 6000000 4000000
## 7 7000000 6100000
## 8 8000000 7000000
## 9 9000000 6500000
## 10 10000000 8000000
#Plot data in graphic
attach(data)
plot(Income, Expenditure, main="Scatter Plot",
xlab="Income For a Month ", ylab="Expenditure For a Month ", pch=19)
#Fit a linear curve
abline(lm(Expenditure~Income), col="red")
Hopefully, this explanation is useful for us ^_^ ~Prana Ugi~