为什么在R中的heatmap.2无法读取数字数据框?

时间:2013-11-29 06:42:35

标签: r plot heatmap gplots

我有以下数据

GOBPID  Term    col1 col2 col3 col4 col5
GO:0001659  temperature_homeostasis 3.49690559977475    0   0   0   0
GO:0001660  fever_generation    3.22606939096511    0   0   0   0

我试图用heatmap.2函数读取:

library("gplots")
dat <- read.table("http://dpaste.com/1486837/plain/",header=TRUE)
dat   <- dat[,!names(dat) %in% c("GOBPID")];
dat2 <- dat[,-1]
rownames(dat2)<-dat[,1]
heatmap.2(dat2,symm=FALSE,trace="none");

根据我的理解,它应该正确读取data.frame。 但为什么失败了呢?

Error in heatmap.2(dat, symm = FALSE, trace = "none") : 
  `x' must be a numeric matrix

更新 我觉得这很奇怪,因为这项工作,

library("gplots")
round(Ca <- cor(attitude), 2)
heatmap.2(Ca, symm = FALSE, margins = c(6,6)) 

Ca的结构与我的dat2相同,不是吗?

1 个答案:

答案 0 :(得分:7)

函数heatmap.2()期望x将是数字矩阵。因此,您需要将数据框dat2转换为函数as.matrix()的矩阵。

heatmap.2(as.matrix(dat2),symm=FALSE,trace="none")

enter image description here