Entering edit mode
8.4 years ago
sparrowquality
▴
20
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.
Could you post a subset of your data_matrix :
data_matrix[1:10,]
. And also could you do is(data_matrix)This looks like your csv file, not the output of R
data_matrix[1:10,]
From the docs:
You may find this blog post enlightening.
Til this time it worked, but if I delete it it is still not doing the cluster analysis and the heatmap..
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.
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.
Yes, I realized as well. CSV made by old MS Excell is working...with new versions not. THX your help.