#Package
library(ggplot2)
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
#Input Data
data=read.table(file.choose(), header=T)
data
## Y X1 X2 X3
## 1 57.5 78 2.75 29.5
## 2 52.8 69 2.15 26.3
## 3 61.3 77 4.41 32.2
## 4 67.0 88 5.52 36.5
## 5 53.5 67 3.21 27.2
## 6 62.7 80 4.32 27.7
## 7 56.2 74 2.31 28.3
## 8 68.5 94 4.30 30.3
## 9 69.2 102 3.71 28.7
#MEMBUAT SCATTER PLOT DENGAN PACKAGE lmtest
plot(data$X1, data$Y, xlab="X1", ylab="Y", main="SCATTER PLOT X1 VS Y")
abline(lm(data$Y~data$X1), col="orange", lwd=4)

plot(data$X2, data$Y, xlab="X2", ylab="Y", main="SCATTER PLOT X2 VS Y")
abline(lm(data$Y~data$X2), col="maroon", lwd=4)

plot(data$X3, data$Y, xlab="X2", ylab="Y", main="SCATTER PLOT X3 VS Y")
abline(lm(data$Y~data$X3), col="navy", lwd=4)

#MEMBUAT SCATTER PLOT DENGAN PACKAGE ggplot2
#X1 VS Y
ggplot(data, aes(x = X1, y = Y, group = 1)) +
geom_point(color = "pink", size = 2) +
geom_smooth(method = "lm", colour = "navy") +
labs(title = "Scatter Plot X1 VS Y",
x = "X1", y = "Y") +
theme_classic(base_size = 13)
## `geom_smooth()` using formula = 'y ~ x'

#X2 VS Y
ggplot(data, aes(x = X2, y = Y, group = 1)) +
geom_point(color = "lightblue", size = 2) +
geom_smooth(method = "lm", colour = "orange") +
labs(title = "Scatter Plot X2 VS Y",
x = "X2", y = "Y") +
theme_classic(base_size = 13)
## `geom_smooth()` using formula = 'y ~ x'

#X3 VS Y
ggplot(data, aes(x = X3, y = Y, group = 1)) +
geom_point(color = "lightgreen", size = 2) +
geom_smooth(method = "lm", colour = "maroon") +
labs(title = "Scatter Plot X3 VS Y",
x = "X3", y = "Y") +
theme_classic(base_size = 13)
## `geom_smooth()` using formula = 'y ~ x'
