我一直在尝试尽量减少对 Excel 的使用,转而使用 R,但在显示简单的数据单元格时仍然遇到困难,而这通常是分析的最后一步所需要的。以下示例是我想要破解的示例,因为它将帮助我切换到 R 来完成工作流程的这一关键部分。
我想说明 R 中的以下相关矩阵:
matrix_values <- c(
NA,1.54,1.63,1.15,0.75,0.78,1.04,1.2,0.94,0.89,
17.95,1.54,NA,1.92,1.03,0.78,0.89,0.97,0.86,1.27,
0.95,25.26,1.63,1.92,NA,0.75,0.64,0.61,0.9,0.88,
1.18,0.74,15.01,1.15,1.03,0.75,NA,1.09,1.03,0.93,
0.93,0.92,0.86,23.84,0.75,0.78,0.64,1.09,NA,1.2,
1.01,0.85,0.9,0.88,30.4,0.78,0.89,0.61,1.03,1.2,
NA,1.17,0.86,0.95,1.02,17.64,1.04,0.97,0.9,0.93,
1.01,1.17,NA,0.94,1.09,0.93,17.22,1.2,0.86,0.88,
0.93,0.85,0.86,0.94,NA,0.95,0.96,24.01,0.94,1.27,
1.18,0.92,0.9,0.95,1.09,0.95,NA,1.25,21.19,0.89,
0.95,0.74,0.86,0.88,1.02,0.93,0.96,1.25,NA,18.14)
cor_matrix <- matrix(matrix_values, ncol = 10, nrow = 11)
item_names <- c('Item1','Item2','Item3','Item4','Item5',
'Item6','Item7','Item8','Item9','Item10')
colnames(cor_matrix) <- item_names
rownames(cor_matrix) <- c(item_names, "Size")
单元格应根据其等级进行着色(例如,>95% 为完全绿色,
I have made in Excel the output that I would like to have:
![correlation matrix](https://p.twimg.com/AyQR9jTCIAA8XXq.png)
Ideally, I would also like to highlight correlation groups (either manually or by script), like in the following illustration:
![correlation matrix with highlights](https://p.twimg.com/AyQSFVYCAAE_hr5.png)