R stat heatmap problem
1
1
Entering edit mode
7.9 years ago

I am using R for cluster analysis visualized by heatmap. Previously it worked perfectly, but reinstalling the software (and the whole system) started to bring errors. Here is the script:

library("gplots")
library("amap")
setwd("C:/Users/Zed/Documents/R/")
data_matrix=read.csv(file=("f:/CE_FASC.csv"), row.names=1)
marker_names=rownames(data_matrix)
sample_ids=colnames(data_matrix)
#mydist=function(c) {dist(c,method="euclidian")}
mydist=distfun = function(matrix) as.dist(Dist(matrix, method = "spearman"))
#myclust=function(c) {hclust(c,method="average")}
myclust=function(c) {hclust(c,method="complete")}
pdf(file="result1.pdf")
main_title="heatmap of clustered markers"
par(cex.main=1)
heatmap.2(as.matrix(data_matrix), hclustfun=myclust, distfun=mydist, na.rm = TRUE, scale="none", dendrogram="column", margins=c(6,6), 
Rowv=TRUE, Colv=TRUE, symbreaks=FALSE, key=TRUE, symkey=FALSE, 
density.info="none", trace="none", main=main_title, labCol=sample_ids, labRow=marker_names, cexRow=1, col=rev(heat.colors(75)))
dev.off()*

Than the error:

Error in heatmap.2(as.matrix(data_matrix), hclustfun = myclust, distfun = mydist, : `x' must be a numeric matrix

The source file (csv) is ok.

R • 7.4k views
ADD COMMENT
0
Entering edit mode

Could you post a subset of your data_matrix : data_matrix[1:10,] . And also could you do is(data_matrix)

ADD REPLY
0
Entering edit mode
"D1,D2,D3,D4
CD34,0,0,0,0
CD44,64,93,84,33
CD47,90,93,90,84
CD54,51,78,42,47
CD73,91,92,89,86
CD90,12,17,0,0
CD105,51,78,69,0
CD106,41,39,73,0
CD112,73,78,83,78
CD146,73,45,54,0
CD166,75,79,84,78
CD325,76,62,89,79"
ADD REPLY
0
Entering edit mode

This looks like your csv file, not the output of R data_matrix[1:10,]

ADD REPLY
0
Entering edit mode

From the docs:

as.matrix is a generic function. The method for data frames will return a character matrix if there is only atomic columns and any non-(numeric/logical/complex) column...

You may find this blog post enlightening.

ADD REPLY
0
Entering edit mode

Til this time it worked, but if I delete it it is still not doing the cluster analysis and the heatmap..

ADD REPLY
0
Entering edit mode

I don't understand. What worked and what did you delete ? Most likely, the integers in your data frame are treated as factor levels and converted to character type. Try the data.matrix() function which tries to coerce a data frame to a numeric matrix.

ADD REPLY
0
Entering edit mode

Your code works as it is with me, I got the mentioned error only when I remove the function as.matrix.

I can only conclude that your csv file is the problem. Did the code work previously with this particular file or other files.

ADD REPLY
0
Entering edit mode

Yes, I realized as well. CSV made by old MS Excell is working...with new versions not. THX your help.

ADD REPLY
1
Entering edit mode
7.9 years ago
"D1,D2,D3,D4
CD34,0,0,0,0
CD44,64,93,84,33
CD47,90,93,90,84
CD54,51,78,42,47
CD73,91,92,89,86
CD90,12,17,0,0
CD105,51,78,69,0
CD106,41,39,73,0
CD112,73,78,83,78
CD146,73,45,54,0
CD166,75,79,84,78
CD325,76,62,89,79"
ADD COMMENT
0
Entering edit mode

Classical heat map plot with row.names=1 and header=T and then view the matrix and plot the heatmap and see if you can see them or not. Do you have a row with all 0 then filter row with all 0 since they will creat NA error

ADD REPLY

Login before adding your answer.

Traffic: 2618 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