library(ggstatsplot)
## Warning: пакет 'ggstatsplot' был собран под R версии 4.2.2
## You can cite this package as:
## Patil, I. (2021). Visualizations with statistical details: The 'ggstatsplot' approach.
## Journal of Open Source Software, 6(61), 3167, doi:10.21105/joss.03167
library(AER)
## Загрузка требуемого пакета: car
## Загрузка требуемого пакета: carData
## Загрузка требуемого пакета: lmtest
## Загрузка требуемого пакета: zoo
##
## Присоединяю пакет: 'zoo'
## Следующие объекты скрыты от 'package:base':
##
## as.Date, as.Date.numeric
## Загрузка требуемого пакета: sandwich
## Загрузка требуемого пакета: survival
library(ggplot2)
## Warning: пакет 'ggplot2' был собран под R версии 4.2.1
library(devtools)
## Загрузка требуемого пакета: usethis
#devtools::install_github("kassambara/ggcorrplot")
library(ggcorrplot)
data("DoctorVisits")
#перевод в формат для корреляции
DoctorVisits1 <- DoctorVisits
head(DoctorVisits1)
## visits gender age income illness reduced health private freepoor freerepat
## 1 1 female 0.19 0.55 1 4 1 yes no no
## 2 1 female 0.19 0.45 1 2 1 yes no no
## 3 1 male 0.19 0.90 3 0 0 no no no
## 4 1 male 0.19 0.15 1 0 0 no no no
## 5 1 male 0.19 0.45 2 5 1 no no no
## 6 1 female 0.19 0.35 5 1 9 no no no
## nchronic lchronic
## 1 no no
## 2 no no
## 3 no no
## 4 no no
## 5 yes no
## 6 yes no
DoctorVisits1$gender <- ifelse(DoctorVisits1$gender == "female", 1, 0)
DoctorVisits1$private <- ifelse(DoctorVisits1$private == "yes", 1, 0)
DoctorVisits1$freepoor <- ifelse(DoctorVisits1$freepoor == "yes", 1, 0)
DoctorVisits1$freerepat <- ifelse(DoctorVisits1$freerepat == "yes", 1, 0)
DoctorVisits1$nchronic <- ifelse(DoctorVisits1$nchronic == "yes", 1, 0)
DoctorVisits1$lchronic <- ifelse(DoctorVisits1$lchronic == "yes", 1, 0)
#корреляция через ggcorrmat
data("DoctorVisits")
ggcorrmat(data = DoctorVisits1,
colors = c("darkblue", "white", "darkred"))

#корреляция через ggcorrplot
corr <- cor(DoctorVisits1)
#p-value
p.mat <- cor_pmat(DoctorVisits1)
ggcorrplot(corr, hc.order = TRUE, type = "lower",
lab = TRUE, p.mat = p.mat, colors = c("#c44a9a", "#f0dff2", "#8a9bab"))
