Question: R stat heatmap problem
1
gravatar for sparrowquality
3.5 years ago by
sparrowquality20 wrote:

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 • 4.2k views
ADD COMMENTlink modified 3.5 years ago • written 3.5 years ago by sparrowquality20

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

ADD REPLYlink modified 3.5 years ago • written 3.5 years ago by Nicolas Rosewick8.5k
"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 REPLYlink written 3.5 years ago by sparrowquality20

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

ADD REPLYlink written 3.5 years ago by Jean-Karim Heriche21k

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 REPLYlink written 3.5 years ago by Jean-Karim Heriche21k

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

ADD REPLYlink written 3.5 years ago by sparrowquality20

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 REPLYlink written 3.5 years ago by Jean-Karim Heriche21k

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 REPLYlink written 3.5 years ago by H.Hasani810

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

ADD REPLYlink written 3.5 years ago by sparrowquality20
1
gravatar for sparrowquality
3.5 years ago by
sparrowquality20 wrote:
"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 COMMENTlink written 3.5 years ago by sparrowquality20

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 REPLYlink written 3.5 years ago by ivivek_ngs4.8k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2114 users visited in the last hour