Why heatmap.2 in R failed to read the numeric data frame?
gplots, heatmap, plot, r
Solution
Function `heatmap.2()` expects that x will be numeric matrix. So you need to convert your data frame `dat2` to matrix with function `as.matrix()`.
heatmap.2(as.matrix(dat2),symm=FALSE,trace="none")
Problem
I have the following data ``` 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 ``` which I tried to read with heatmap.2 function: ``` 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"); ``` In my understanding it should read the data.frame correctly. But why it failed? ``` Error in heatmap.2(dat, symm = FALSE, trace = "none") : `x' must be a numeric matrix ``` Update: I find it strange because this work, ``` library("gplots") round(Ca <- cor(attitude), 2) heatmap.2(Ca, symm = FALSE, margins = c(6,6)) ``` The structure of `Ca` is the same with my `dat2`, no?