我有以下数据
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
,不是吗?
函数heatmap.2()
期望x将是数字矩阵.因此,您需要dat2
使用函数将数据框转换为矩阵as.matrix()
.
heatmap.2(as.matrix(dat2),symm=FALSE,trace="none")