使用R生成热图

时间:2013-12-11 19:43:18

标签: r heatmap

我想要一个帮助,我必须制作热图。我在R中使用以下命令生成矩阵,但它返回错误,我无法弄明白。 你能告诉我出了什么问题吗?

还请建议我如何生成热图。

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"

1 个答案:

答案 0 :(得分:0)

使用它来创建矩阵:

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")

产生这个。这是你的想法吗?