library(readxl)
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
##
## ======================
## 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
## ======================
# 1. Baca data dari Excel
data_bayi <- read_excel("bayi.xlsx")
# 2. Konversi seluruh kolom menjadi numerik secara paksa
data_bayi_num <- as.data.frame(lapply(data_bayi, function(x) as.numeric(as.character(x))))
## Warning in FUN(X[[i]], ...): NAs introduced by coercion
# 3. Hitung Matriks Korelasi (Gunakan method = "spearman" jika ingin Korelasi Spearman)
matriks_korelasi <- cor(data_bayi_num, method = "spearman", use = "complete.obs")
# 4. Tampilkan Heatmap
heatmaply(
matriks_korelasi,
main = "Heatmap Matriks Korelasi Spearman",
dendrogram = "none",
cellnote = round(matriks_korelasi, 2),
cellnote_color = "white", # Mengubah warna teks angka menjadi putih agar kontras
colors = viridis(100),
limits = c(-1, 1)
)