a0 <- read.csv(file = "C:/Users/81809/Downloads/RStudio/heart.data.csv")
a <- a0[ ,-1]
library(DT)
datatable(a)
x <- a$biking
y <- a$smoking
z <- a$heart.disease
cor(x,y)
## [1] 0.01513618
cor(x,z)
## [1] -0.9354555
cor(y,z)
## [1] 0.309131
r <- cor(a)
r
## biking smoking heart.disease
## biking 1.00000000 0.01513618 -0.9354555
## smoking 0.01513618 1.00000000 0.3091310
## heart.disease -0.93545547 0.30913098 1.0000000
library(kableExtra)
kable(round(r,2),caption = '相関表') |> kable_classic('striped',full_width = F)
相関表
|
biking
|
smoking
|
heart.disease
|
biking
|
1.00
|
0.02
|
-0.94
|
smoking
|
0.02
|
1.00
|
0.31
|
heart.disease
|
-0.94
|
0.31
|
1.00
|
コメント
bikingとsmokingには、相関がない
bikingとheart.diseaseには、強い負の相関がある
smokingとheart.diseaseには、弱い正の相関がある
library(psych)
pairs.panels(a)

cor.plot(a)

library(corrplot)
corrplot.mixed(r,lower = 'ellips',upper = 'number')

library(plotly)
kyokasho <- list(size = 11,color = 'blue',family = 'UD Digi Kyokasho NK-R')
plot_ly(x = rownames(r),
y = colnames(r),
z = as.matrix(r),
text = paste(r),
type = 'heatmap') |>
layout(font = kyokasho,
title = '主タイトル',
xaxis = list(title = 'x軸カテゴリラベル'),
yaxis = list(title = 'y軸カテゴリラベル'))