8

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?

neversaint
  • 60,904
  • 137
  • 310
  • 477
  • 1
    There are two problems - first column of dat still contains characters and it is dataframe but matrix is needed. Try heatmap.2(as.matrix(dat[,-1]),symm=FALSE,trace="none") – Didzis Elferts Nov 29 '13 at 06:50
  • @DidzisElferts: Thanks. But I want the "term" as the description. See my updated example where the 'characters' column works. – neversaint Nov 29 '13 at 09:39
  • 1
    dat2 is data frame but Ca is matrix. Error message say that x MUST be a numeric matrix! – Didzis Elferts Nov 29 '13 at 09:41

1 Answers1

7

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

enter image description here

Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201