How To Cluster .Csv Raw Data And Generate Heatmap Using Heatmap.2 Function In Package Gplots?
2
0
Entering edit mode
11.2 years ago

I am a green hand for using R-based software to analyze my data, which are all saved in csv format. My question is well described in the title of this post. Of course, it is also welcome absolutely if you can provide solutions using different methods. Your prompt response will be highly appreciated.

Best regards,

Jeff

Actually I tested the codes that I got from help pages of gplots. But I failed to get image even with a small testing file. The following is my testing file saved as try.csv.

Gene,BB8,BB12,BB28,BB55,BB70,BB106,Pool_B
Du123.6_C_SA,207,352,165,84,147,198,182
Du151.2_C_SA,196,1555,2529,818,241,487,518
Du156.12*_C_SA,369,390,238,336,406,258,231
Du172.17*_C_SA,429,884,499,196,549.550.315

The codes I used are:

>library(gplots)
>data<-read.table("try.csv", header=T)
>heatmap.2(as.matrix(data))

After running the heatmap.2 function, I got error message which is:

Error in heatmap.2(as.matrix(data)) : `x' must be a numeric matrix

Is there any problem with my testing file?

Thanks for your considerations in advance.

Jeff

clustering • 12k views
ADD COMMENT
2
Entering edit mode

I hope declaring the rownames() would help

ADD REPLY
0
Entering edit mode

Check if your imported data contains numeric columns: sapply(data, class)

ADD REPLY
3
Entering edit mode
11.2 years ago

As ancient_learner alluded, the issue is the row names. The following will work:

library(gplots)
data <- read.csv("blah", header=T, row.names=1)
heatmap.2(as.matrix(data))

As a rule of thumb, you can usually figure out what's causing this sort of error by simply looking at a snippet of the matrix/data.frame/object.

ADD COMMENT
0
Entering edit mode
11.2 years ago

I solved the issue with you guys' suggestion. I think to declare row.names=1 is critical if you have input in the A1 cell. Thanks!

ADD COMMENT
0
Entering edit mode

That means, you should validate dpryan's answer. This would be better a comment not an answer. The problem was that you get (or better R coerced the data.frame into) a character matrix, when not solely numeric values are present in a data.frame that read.csv returns. A matrix has to consist of elements of identical type, while a data.frame can hold columns of different types. read.csv default behavior is: "If there is a header and the first row contains one fewer field than the number of columns, the first column in the input is used for the row names. Otherwise if row.names is missing, the rows are numbered."

ADD REPLY

Login before adding your answer.

Traffic: 1927 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6