<!-- README.md is generated from README.Rmd. Please edit that file -->
[![R build
status](https://github.com/kassambara/ggcorrplot/workflows/R-CMD-check/badge.svg)](https://github.com/kassambara/ggcorrplot/actions)
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/ggcorrplot)](https://cran.r-project.org/package=ggcorrplot)
[![CRAN
Checks](https://cranchecks.info/badges/summary/ggcorrplot)](https://cran.r-project.org/web/checks/check_results_ggcorrplot.html)
[![Downloads](https://cranlogs.r-pkg.org/badges/ggcorrplot)](https://cran.r-project.org/package=ggcorrplot)
[![Total
Downloads](https://cranlogs.r-pkg.org/badges/grand-total/ggcorrplot?color=orange)](https://cranlogs.r-pkg.org/badges/grand-total/ggcorrplot)
# ggcorrplot: Visualization of a correlation matrix using ggplot2
The **ggcorrplot** package can be used to **visualize easily** a
**correlation matrix** using **ggplot2**. It provides a solution for
**reordering** the correlation matrix and displays the **significance
level** on the correlogram. It includes also a function for computing a
matrix of **correlation p-values**.
Find out more at
<http://www.sthda.com/english/wiki/ggcorrplot-visualization-of-a-correlation-matrix-using-ggplot2>.
## Installation and loading
ggcorrplot can be installed from `CRAN` as follow:
``` r
install.packages("ggcorrplot")
```
Or, install the latest version from GitHub:
``` r
# Install
if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/ggcorrplot")
```
``` r
# Loading
library(ggcorrplot)
```
## Getting started
### Compute a correlation matrix
The *mtcars* data set will be used in the following R code. The function
**cor\_pmat()** \[in **ggcorrplot**\] computes a matrix of correlation
p-values.
``` r
# Compute a correlation matrix
data(mtcars)
corr <- round(cor(mtcars), 1)
head(corr[, 1:6])
#> mpg cyl disp hp drat wt
#> mpg 1.0 -0.9 -0.8 -0.8 0.7 -0.9
#> cyl -0.9 1.0 0.9 0.8 -0.7 0.8
#> disp -0.8 0.9 1.0 0.8 -0.7 0.9
#> hp -0.8 0.8 0.8 1.0 -0.4 0.7
#> drat 0.7 -0.7 -0.7 -0.4 1.0 -0.7
#> wt -0.9 0.8 0.9 0.7 -0.7 1.0
# Compute a matrix of correlation p-values
p.mat <- cor_pmat(mtcars)
head(p.mat[, 1:4])
#> mpg cyl disp hp
#> mpg 0.000000e+00 6.112687e-10 9.380327e-10 1.787835e-07
#> cyl 6.112687e-10 0.000000e+00 1.802838e-12 3.477861e-09
#> disp 9.380327e-10 1.802838e-12 0.000000e+00 7.142679e-08
#> hp 1.787835e-07 3.477861e-09 7.142679e-08 0.000000e+00
#> drat 1.776240e-05 8.244636e-06 5.282022e-06 9.988772e-03
#> wt 1.293959e-10 1.217567e-07 1.222320e-11 4.145827e-05
```
## Correlation matrix visualization
``` r
# Visualize the correlation matrix
# --------------------------------
# method = "square" (default)
ggcorrplot(corr)
```
![ggcorrplot: visualize correlation matrix using
ggplot2](tools/README-demo-ggcorrplot-1.png)
``` r
# method = "circle"
ggcorrplot(corr, method = "circle")
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
```
![ggcorrplot: visualize correlation matrix using
ggplot2](tools/README-demo-ggcorrplot-2.png)
``` r
# Reordering the correlation matrix
# --------------------------------
# using hierarchical clustering
ggcorrplot(corr, hc.order = TRUE, outline.color = "white")
```
![ggcorrplot: visualize correlation matrix using
ggplot2](tools/README-demo-ggcorrplot-3.png)
``` r
# Types of correlogram layout
# --------------------------------
# Get the lower triangle
ggcorrplot(corr,
hc.order = TRUE,
type = "lower",
outline.color = "white")
```
![ggcorrplot: visualize correlation matrix using
ggplot2](tools/README-demo-ggcorrplot-4.png)
``` r
# Get the upper triangle
ggcorrplot(corr,
hc.order = TRUE,
type = "upper",
outline.color = "white")
```
![ggcorrplot: visualize correlation matrix using
ggplot2](tools/README-demo-ggcorrplot-5.png)
``` r
# Change colors and theme
# --------------------------------
# Argument colors
ggcorrplot(
corr,
hc.order = TRUE,
type = "lower",
outline.color = "white",
ggtheme = ggplot2::theme_gray,
colors = c("#6D9EC1", "white", "#E46726")
)
```
![ggcorrplot: visualize correlation matrix using
ggplot2](tools/README-demo-ggcorrplot-6.png)
``` r
# Add correlation coefficients
# --------------------------------
# argument lab = TRUE
ggcorrplot(corr,
hc.order = TRUE,
type = "lower",
lab = TRUE)
```
![ggcorrplot: visualize correlation matrix using
ggplot2](tools/README-demo-ggcorrplot-7.png)
``` r
# Add correlation significance level
# --------------------------------
# Argument p.mat
# Barring the no significant coefficient
ggcorrplot(corr,
hc.order = TRUE,
type = "lower",
p.mat = p.mat)
```
![ggcorrplot: visualize correlation matrix using
ggplot2](tools/README-demo-ggcorrplot-8.png)
``` r
# Leave blank on no significant coefficient
ggcorrplot(
corr,
p.mat = p.mat,
hc.order = TRUE,
type = "lower",
insig = "blank"
)
```
![ggcorrplot: visualize correlation matrix using
ggplot2](tools/README-demo-ggcorrplot-9.png)
没有合适的资源?快使用搜索试试~ 我知道了~
使用ggplot2可视化相关矩阵_R_下载.zip
共64个文件
png:28个
html:6个
svg:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 79 浏览量
2023-04-13
23:36:34
上传
评论
收藏 1.71MB ZIP 举报
温馨提示
使用ggplot2可视化相关矩阵_R_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
使用ggplot2可视化相关矩阵_R_下载.zip (64个子文件)
ggcorrplot-master
tools
README-demo-ggcorrplot-3.png 32KB
README-demo-ggcorrplot-4.png 29KB
README-demo-ggcorrplot-6.png 29KB
README-demo-ggcorrplot-9.png 29KB
README-demo-ggcorrplot-1.png 32KB
README-demo-ggcorrplot-2.png 113KB
README-demo-ggcorrplot-8.png 32KB
README-demo-ggcorrplot-7.png 59KB
README-demo-ggcorrplot-5.png 29KB
man
ggcorrplot.Rd 5KB
.github
workflows
R-CMD-check.yaml 2KB
.gitignore 7B
ggcorrplot.Rproj 409B
tests
testthat.R 64B
spelling.R 149B
testthat
test-vdiffr.R 698B
_snaps
vdiffr
ggcorrplot-works-hc.svg 30KB
ggcorrplot-works-default.svg 30KB
ggcorrplot-works-circle.svg 23KB
.Rbuildignore 153B
docs
pkgdown.js 3KB
tools
README-demo-ggcorrplot-3.png 32KB
README-demo-ggcorrplot-4.png 29KB
README-demo-ggcorrplot-6.png 29KB
README-demo-ggcorrplot-9.png 29KB
README-demo-ggcorrplot-1.png 32KB
README-demo-ggcorrplot-8 2.png 32KB
README-demo-ggcorrplot-2.png 113KB
README-demo-ggcorrplot-7.png 59KB
README-demo-ggcorrplot-5.png 29KB
docsearch.css 11KB
pkgdown.yml 88B
bootstrap-toc.js 5KB
pkgdown.css 7KB
404.html 5KB
news
index.html 11KB
favicon.ico 1KB
bootstrap-toc.css 2KB
index.html 18KB
link.svg 810B
docsearch.js 2KB
reference
ggcorrplot-6.png 73KB
ggcorrplot-3.png 78KB
ggcorrplot-7.png 131KB
ggcorrplot-4.png 72KB
ggcorrplot.html 23KB
ggcorrplot-9.png 72KB
ggcorrplot-10.png 184KB
ggcorrplot-2.png 270KB
ggcorrplot-5.png 72KB
index.html 5KB
ggcorrplot-8.png 80KB
ggcorrplot-1.png 78KB
authors.html 5KB
R
ggcorrplot.R 12KB
NEWS.md 3KB
cran-comments.md 315B
_pkgdown.yml 149B
NAMESPACE 98B
.gitignore 65B
DESCRIPTION 1KB
README.md 5KB
inst
WORDLIST 121B
README.Rmd 4KB
共 64 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功