optiforziyan的个人博客分享 http://blog.sciencenet.cn/u/optiforziyan

博文

[转载]Seven Easy Graphs to Visualize Correlation Matrices in R

已有 1576 次阅读 2020-3-5 12:44 |系统分类:科研笔记| R语言 |文章来源:转载

I want to share seven insightful correlation matrix visualizations that are beautiful and simple to build with only one line of code. However, each graph does have many customization options for power users to explore. We’ll use the built in mtcars dataset that consists of fuel consumption and 10 variables of automobile design, such as number of cylinders, horsepower, engine displacement, etc., for 32 automobiles. We’ll start by saving five variables to a new object called mydata. We’ll use the mydata object in all our examples.


mydata <- mtcars[, c('mpg', 'cyl', 'disp', 'hp', 'carb')]

PerformanceAnalytics Package

We’ll start with the best implementation, in my opinion, from the PerformanceAnalytics package. This graph provides the following information:

1.Correlation coefficient (r) - The strength of the relationship. 2.p-value - The significance of the relationship. Significance codes 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1 3.Histogram with kernel density estimation and rug plot. 4.Scatter plot with fitted line.

library("PerformanceAnalytics")
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
chart.Correlation(mydata, histogram=TRUE, pch=19)





https://blog.sciencenet.cn/blog-3429889-1221904.html


下一篇:物种分布模型中预测变量多重共线性处理(栅格数据)
收藏 IP: 222.212.115.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-25 14:55

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部