Biplot adalah salah satu metode visualisasi dalam analisis data multivariat. Biplot menampilkan hubungan antara variabel (peubah) dan observasi (pengamatan) dalam satu diagram dua dimensi. Biplot biasanya digunakan dalam Analisis Komponen Utama (AKU/PCA) atau metode lain yang mereduksi dimensi data.
Dengan biplot, kita dapat memahami pola data, hubungan antar variabel, serta perbedaan antar observasi secara visual.
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## 1 5.1 3.5 1.4 0.2
## 2 4.9 3.0 1.4 0.2
## 3 4.7 3.2 1.3 0.2
## 4 4.6 3.1 1.5 0.2
## 5 5.0 3.6 1.4 0.2
## 6 5.4 3.9 1.7 0.4
# Perform PCA
pca_result <- prcomp(iris_data, scale. = TRUE)
# Lihat standard deviation (sdev)
pca_result$sdev
## [1] 1.7083611 0.9560494 0.3830886 0.1439265
# Variansi yang dijelaskan oleh setiap PC
explained_variance <- (pca_result$sdev)^2
proportion_variance <- explained_variance / sum(explained_variance)
proportion_variance
## [1] 0.729624454 0.228507618 0.036689219 0.005178709
# Scree Plot untuk visualisasi proporsi variansi
plot(proportion_variance, type = "b", xlab = "Principal Component",
ylab = "Proportion of Variance Explained", main = "Scree Plot")
## PC1 PC2 PC3 PC4
## Sepal.Length 0.5210659 -0.37741762 0.7195664 0.2612863
## Sepal.Width -0.2693474 -0.92329566 -0.2443818 -0.1235096
## Petal.Length 0.5804131 -0.02449161 -0.1421264 -0.8014492
## Petal.Width 0.5648565 -0.06694199 -0.6342727 0.5235971
Biplot di atas menampilkan skor dan loading dari AKU.
## Warning: package 'ggplot2' was built under R version 4.3.3
## Warning: package 'ggfortify' was built under R version 4.3.3
# Create a biplot using ggplot2 and ggfortify
autoplot(pca_result, data = iris, colour = 'Species',
loadings = TRUE, loadings.label = TRUE, loadings.label.size = 3)
## Warning: package 'FactoMineR' was built under R version 4.3.3
## Warning: package 'factoextra' was built under R version 4.3.3
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
# Perform PCA using FactoMineR
pca_result_fm <- PCA(iris_data, scale.unit = TRUE, graph = FALSE)
# Create a biplot using FactoMineR and factoextra
fviz_pca_biplot(pca_result_fm, repel = TRUE,
col.var = "blue", # Variables color
col.ind = iris$Species, # Individuals color by groups
palette = c("#00AFBB", "#E7B800", "#FC4E07"),
addEllipses = TRUE, ellipse.level = 0.95)