# 2. Panggil library
library(heatmaply)
## Warning: package 'heatmaply' was built under R version 4.5.3
## Loading required package: plotly
## Warning: package 'plotly' was built under R version 4.5.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.5.3
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
## Loading required package: viridis
## Warning: package 'viridis' was built under R version 4.5.3
## Loading required package: viridisLite
## Warning: package 'viridisLite' was built under R version 4.5.3
##
## ======================
## Welcome to heatmaply version 1.6.0
##
## Type citation('heatmaply') for how to cite the package.
## Type ?heatmaply for the main documentation.
##
## The github page is: https://github.com/talgalili/heatmaply/
## Please submit your suggestions and bug-reports at: https://github.com/talgalili/heatmaply/issues
## You may ask questions at stackoverflow, use the r and heatmaply tags:
## https://stackoverflow.com/questions/tagged/heatmaply
## ======================
# 3. Input data sesuai gambar
data <- data.frame(
Y = c(57.5, 52.8, 61.3, 67.0, 53.5, 62.7, 56.2, 68.5, 69.2),
X1 = c(78, 69, 77, 88, 67, 80, 74, 94, 102),
X2 = c(2.75, 2.15, 4.41, 5.52, 3.21, 4.32, 2.31, 4.30, 3.71),
X3 = c(29.5, 26.3, 32.2, 36.5, 27.2, 27.7, 28.3, 30.3, 28.7)
)
# 4. Hitung matriks korelasi
matriks_korelasi <- cor(data)
# 5. Tampilkan angka korelasi di console (opsional)
print(round(matriks_korelasi, 3))
## Y X1 X2 X3
## Y 1.000 0.947 0.761 0.560
## X1 0.947 1.000 0.534 0.390
## X2 0.761 0.534 1.000 0.784
## X3 0.560 0.390 0.784 1.000
# 6. Buat heatmap korelasi interaktif
heatmaply(
matriks_korelasi,
limits = c(-1, 1), # Skala korelasi dari -1 sampai 1
colors = cool_warm, # Gradasi warna
dendrogram = "none", # Matriks bersih tanpa pohon kluster
cellnote = round(matriks_korelasi, 2), # Memunculkan angka korelasi di dalam kotak
main = "Heatmap Matriks Korelasi"
)# 1. Install package heatmaply (cukup jalankan sekali)
install.packages("heatmaply")
## Warning: package 'heatmaply' is in use and will not be installed
# 2. Panggil library
library(heatmaply)
# 3. Input data sesuai gambar
data <- data.frame(
Y = c(57.5, 52.8, 61.3, 67.0, 53.5, 62.7, 56.2, 68.5, 69.2),
X1 = c(78, 69, 77, 88, 67, 80, 74, 94, 102),
X2 = c(2.75, 2.15, 4.41, 5.52, 3.21, 4.32, 2.31, 4.30, 3.71),
X3 = c(29.5, 26.3, 32.2, 36.5, 27.2, 27.7, 28.3, 30.3, 28.7)
)
# 4. Hitung matriks korelasi
matriks_korelasi <- cor(data)
# 5. Tampilkan angka korelasi di console (opsional)
print(round(matriks_korelasi, 3))
## Y X1 X2 X3
## Y 1.000 0.947 0.761 0.560
## X1 0.947 1.000 0.534 0.390
## X2 0.761 0.534 1.000 0.784
## X3 0.560 0.390 0.784 1.000
# 6. Buat heatmap korelasi interaktif
heatmaply(
matriks_korelasi,
limits = c(-1, 1), # Skala korelasi dari -1 sampai 1
colors = cool_warm, # Gradasi warna
dendrogram = "none", # Matriks bersih tanpa pohon kluster
cellnote = round(matriks_korelasi, 2), # Memunculkan angka korelasi di dalam kotak
main = "Heatmap Matriks Korelasi"
)