|| |
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')]
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)
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-4-25 14:55
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社