# Memanggil library ggplot2
library(ggplot2)
# Membaca dataset obesity
obesity <- read.csv(
"Eric_ObesityDataSet_raw_and_data_sinthetic.csv",
sep = ";"
)
# Menampilkan beberapa data pertama
head(obesity)
## Gender Age Height Weight family_history_with_overweight FAVC FCVC NCP
## 1 Female 21 1.62 64.0 yes no 2 3
## 2 Female 21 1.52 56.0 yes no 3 3
## 3 Male 23 1.80 77.0 yes no 2 3
## 4 Male 27 1.80 87.0 no no 3 3
## 5 Male 22 1.78 89.8 no no 2 1
## 6 Male 29 1.62 53.0 no yes 2 3
## CAEC SMOKE CH2O SCC FAF TUE CALC MTRANS
## 1 Sometimes no 2 no 0 1 no Public_Transportation
## 2 Sometimes yes 3 yes 3 0 Sometimes Public_Transportation
## 3 Sometimes no 2 no 2 1 Frequently Public_Transportation
## 4 Sometimes no 2 no 2 0 Frequently Walking
## 5 Sometimes no 2 no 0 0 Sometimes Public_Transportation
## 6 Sometimes no 2 no 0 0 Sometimes Automobile
## NObeyesdad
## 1 Normal_Weight
## 2 Normal_Weight
## 3 Normal_Weight
## 4 Overweight_Level_I
## 5 Overweight_Level_II
## 6 Normal_Weight
ggplot(obesity, aes(x = Age, y = Weight)) +
geom_point(
color = "steelblue",
size = 2.5,
alpha = 0.7
) +
geom_smooth(
method = "lm",
se = FALSE,
color = "red",
linewidth = 1
) +
labs(
title = "Scatter Plot Age dan Weight",
x = "Age (Tahun)",
y = "Weight (kg)"
) +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

ggplot(obesity, aes(x = Height, y = Weight)) +
geom_point(
color = "darkorange",
size = 2.5,
alpha = 0.7
) +
geom_smooth(
method = "lm",
se = FALSE,
color = "blue",
linewidth = 1
) +
labs(
title = "Scatter Plot Height dan Weight",
x = "Height (m)",
y = "Weight (kg)"
) +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

ggplot(obesity, aes(x = Age, y = Height)) +
geom_point(
color = "purple",
size = 2.5,
alpha = 0.7
) +
geom_smooth(
method = "lm",
se = FALSE,
color = "black",
linewidth = 1
) +
labs(
title = "Scatter Plot Age dan Height",
x = "Age (Tahun)",
y = "Height (m)"
) +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
