简体   繁体   English

使用 network_plot 可视化 R 中的相关矩阵

[英]Use network_plot to visualise correlation matrix in R

I want to visualise the correlation matrix of 60+ attributes.我想可视化 60 多个属性的相关矩阵。 I've tried 'library(corrplot)' and the result shows warning: "too many overlap".我试过'library(corrplot)',结果显示警告:“重叠太多”。 Then I tried, which shows a messy plot that the labels are too large and the curves are overlapping.然后我试了一下,显示一个乱七八糟的plot标签太大,曲线重叠。

library(corrr)
data %>% correlate() %>% network_plot(min_cor = 0.4)

I tried to adjust the label size and curve width following https://www.rdocumentation.org/packages/memnet/versions/0.1.0/topics/network_plot , it shows error:我尝试在https://www.rdocumentation.org/packages/memnet/versions/0.1.0/topics/network_plot之后调整 label 大小和曲线宽度,它显示错误:

Error in network_plot(correlate(data), min_cor = 0.4, nod_cex = 2, : unused arguments (nod_cex = 2, lab_cex = 1, lab_lwd = 2) network_plot 中的错误(相关(数据),min_cor = 0.4,nod_cex = 2,:未使用的 arguments(nod_cex = 2,lab_cex = 1,lab_lwd = 2)

在此处输入图像描述

memnet is a deprecated package that has been removed from CRAN so this is normal you can't use the network_plot from this package, but here you are using the network_plot function from the corrr package which haven't the same arguments: https://www.rdocumentation.org/packages/corrr/versions/0.4.3/topics/network_plot memnet is a deprecated package that has been removed from CRAN so this is normal you can't use the network_plot from this package, but here you are using the network_plot function from the corrr package which haven't the same arguments: https:// www.rdocumentation.org/packages/corrr/versions/0.4.3/topics/network_plot

With 60 variables, I don't think network_plot is the best option for visualisation.有 60 个变量,我不认为network_plot是可视化的最佳选择。 However, you can try to use corrplot as follows:但是,您可以尝试按如下方式使用corrplot

#Create a data frame with random values
df=data.frame(replicate(60,sample(0:60,10,rep=TRUE)))
cor=cor(df)
cor2 <- corrplot::corrMatOrder(cor, order = "FPC", hclust.method = "average")
corrplot::corrplot(cor[cor2,cor2], diag = F, type = "lower",
                       method = "color",  mar = c(1,1,3,1), tl.srt = 60, tl.cex = 0.4)

This will produce this graph which will be far more interpretable:这将产生这个更易于解释的图表: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM