if (!require("ggplot2")) install.packages("ggplot2")
## Loading required package: ggplot2
library(ggplot2)

# Import dataset
data_obesity <- read.csv("Eric_ObesityDataSet_raw_and_data_sinthetic.csv", sep = ";")

# Tampilkan 6 baris pertama
head(data_obesity[, c("Age", "Height", "Weight", "Gender")])
##   Age Height Weight Gender
## 1  21   1.62   64.0 Female
## 2  21   1.52   56.0 Female
## 3  23   1.80   77.0   Male
## 4  27   1.80   87.0   Male
## 5  22   1.78   89.8   Male
## 6  29   1.62   53.0   Male
ggplot(data_obesity, aes(x = Height, y = Weight, color = Gender)) +
  geom_point(alpha = 0.5, size = 2) +
  geom_smooth(method = "lm", color = "black", se = TRUE) +
  labs(
    title = "1. Hubungan Tinggi Badan vs Berat Badan",
    x = "Tinggi Badan (m)",
    y = "Berat Badan (kg)",
    color = "Jenis Kelamin"
  ) +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

ggplot(data_obesity, aes(x = Age, y = Weight, color = Gender)) +
  geom_point(alpha = 0.5, size = 2) +
  geom_smooth(method = "loess", color = "darkred", se = TRUE) +
  labs(
    title = "2. Hubungan Usia vs Berat Badan",
    x = "Usia (Tahun)",
    y = "Berat Badan (kg)",
    color = "Jenis Kelamin"
  ) +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

ggplot(data_obesity, aes(x = Age, y = Height, color = Gender)) +
  geom_point(alpha = 0.5, size = 2) +
  geom_smooth(method = "loess", color = "darkgreen", se = TRUE) +
  labs(
    title = "3. Hubungan Usia vs Tinggi Badan",
    x = "Usia (Tahun)",
    y = "Tinggi Badan (m)",
    color = "Jenis Kelamin"
  ) +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'