gpt4 book ai didi

r - 如何关联数据框上的所有列并构建热图?

转载 作者:行者123 更新时间:2023-12-05 02:01:18 28 4
gpt4 key购买 nike

我有一个数据框,其中我的测量值按月份的天数分隔,我想在月份之间建立一个相关矩阵(热图),如下例所示: enter image description here

感谢您的帮助!我的数据头是:

> head(month)
Jan Feb Mar Apr May
1 18.06474972 11.399055 -31.03085327 127.2022133 -3460.850586
2 51.03550959 461.5850525 95.19575119 243.0290451 -2083.35199
3 47.54027748 110.2497387 -74.04249191 546.8690033 -1276.771118
4 340.8937378 282.1457062 74.03128743 322.6983643 -203.3483124
5 247.5398369 30.00830674 370.5808411 416.0554199 121.7065811
6 399.5107269 922.6151428 439.3453064 -35.20425129 -1469.418518
Jun Jul Aug Sep Oct
1 39.49685574 2622.950073 1649.752869 1238.56366 500.0726166
2 380.0546722 2552.876099 2572.219482 525.0535278 1092.828491
3 278.1513977 1118.665558 2370.05896 561.7017517 880.8520813
4 1334.320251 1658.281433 588.7766266 316.3756104 331.518219
5 681.0978546 1830.663025 436.6187897 188.4522657 -106.0038891
6 -69.24006653 1645.978577 2079.013062 -116.1453476 292.2966232
Nov Dec
1 -251.1712646 196.3089867
2 -2490.553711 37.59177971
3 -1460.746155 251.9935303
4 425.8812321 345.0469666
5 253.5491486 -150.1276989
6 2654.713806 -1673.095764

最佳答案

你可以试试下面的方法:

library(pheatmap)
month = data.frame(matrix(runif(120),ncol=12))
colnames(month) = format(ISOdate(2004,1:12,1),"%B")

pheatmap(cor(month),cluster_rows = FALSE, cluster_cols =FALSE)

enter image description here

关于r - 如何关联数据框上的所有列并构建热图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66692904/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com