library(dplyr)
## 
##  次のパッケージを付け加えます: 'dplyr'
##  以下のオブジェクトは 'package:stats' からマスクされています:
## 
##     filter, lag
##  以下のオブジェクトは 'package:base' からマスクされています:
## 
##     intersect, setdiff, setequal, union
d <- read.csv(file = 'https://stats.dip.jp/01_ds/data/heart.data.csv')
              
d <- d %>% select(-X)

library(DT)
datatable(d)
r <- cor(d)
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)
## 
##  次のパッケージを付け加えます: 'kableExtra'
##  以下のオブジェクトは 'package:dplyr' からマスクされています:
## 
##     group_rows
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
library(psych)
pairs.panels(d)

cor.plot(d)

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

library(plotly)
##  要求されたパッケージ ggplot2 をロード中です
## 
##  次のパッケージを付け加えます: 'ggplot2'
##  以下のオブジェクトは 'package:psych' からマスクされています:
## 
##     %+%, alpha
## 
##  次のパッケージを付け加えます: 'plotly'
##  以下のオブジェクトは 'package:ggplot2' からマスクされています:
## 
##     last_plot
##  以下のオブジェクトは 'package:stats' からマスクされています:
## 
##     filter
##  以下のオブジェクトは 'package:graphics' からマスクされています:
## 
##     layout
kyokasho <- list(size = 11, color = 'black', family = 'UD Digi Kyokasho NK-R')


plot_ly(x = colnames(r),
        y = rownames(r),
        z = as.matrix(r),
        text = paste(r),
        type = 'heatmap') %>%
  layout(font = kyokasho,
         title = 'Heart Data',
         xaxis = list(title = 'Data'),
         yaxis = list(title = 'Data'))
#疲れた

#smokingとheart.diseaseは弱い正の相関がある #bikingとsmokingは相関がない #heart.diseaseとbikingは強い負の相関