使用R生成热图 [英] Generating a heatmap using R
本文介绍了使用R生成热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助,我必须制作热点地图.而且我在R中使用以下命令生成矩阵,但是返回了错误,因此我无法弄清楚. 你能告诉我怎么了吗?
I want a help, I have to make heat map. And I am using the following command in R for generating a matrix, but its returning an error, and I am not able to figure it out. Can you please tell me what is wrong?
并且还建议我如何生成热图.
And please also suggest me how to generate a heat map.
mat <- matrix(c(100,49.3,45.71,54.29,97.22,68.57,49.3,100,22.54,26.76,50.7,
33.8,45.71,22.54,100,84.21,44.44,66.67,54.29,26.76,84.21,100,
52.78,79.17,97.22,50.7,44.44,52.78,100,66.67,68.57,33.8,
66.67,79.17,66.67,100), nrow = 6, ncol = 6, byrow = TRUE,
dimnames = list(c(""A_1HJO","B_2L1W","C_1MHS",
"D_1HQY","E_1XU4","F_1JNB""),
c(("A_1HJO","B_2L1W","C_1MHS","D_1HQY","E_1XU4","F_1JNB"))))
Error: unexpected symbol in "49.3,45.71,54.29,97.22,68.57,49.3,100,22.54,
26.76,50.7,33.8,45.71,22.54,100,84.21,44.44,66.67,54.29,26.76,84.21,100,
52.78,79.17,97.22,50.7,44.44,52.78,100,66.67,68.57,33.8,66.67,79.17,66.67,10"
推荐答案
使用此方法创建矩阵:
mat <- matrix(c(100,49.3,45.71,54.29,97.22,68.57,49.3,100,22.54,26.76,50.7,
33.8,45.71,22.54,100,84.21,44.44,66.67,54.29,26.76,84.21,100,
52.78,79.17,97.22,50.7,44.44,52.78,100,66.67,68.57,33.8,
66.67,79.17,66.67,100), nrow = 6, ncol = 6, byrow = TRUE,
dimnames = list(c("A_1HJO","B_2L1W","C_1MHS",
"D_1HQY","E_1XU4","F_1JNB"),
c("A_1HJO","B_2L1W","C_1MHS","D_1HQY","E_1XU4","F_1JNB")))
然后:
library(ggplot2)
library(reshape2)
gg=melt(mat)
ggplot(gg, aes(x=Var1,y=Var2,fill=value))+
geom_tile()+
scale_fill_gradient(low="#ffffaa",high="#cc0000")
产生这个.这就是您的想法吗?
Produces this. Is this what you had in mind?
这篇关于使用R生成热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文