I would like to plot a heatmap on a table imported from MATLAB. The table has explicited rownames and colnames and I have loaded it into R with read.table, and I can run summary(i) and get the numeric summaries for each column:
i = read.table("file.txt",header=TRUE)
But when I try to run heatmap, it complains the converted matrix is not numeric, both with and without rownames.force=TRUE:
is.matrix(as.matrix(i,rownames.force=TRUE))
[1] TRUE
heatmap(as.matrix(i,rownames.force=TRUE))
Error in heatmap(as.matrix(i, rownames.force = TRUE)) :
'x' must be a numeric matrix
I think the problem is that as.matrix tries to convert the non-numeric rowname (or colname, I am not sure anymore :-():
as.matrix(i)[1]
[1] "cluster-594-walk-0161"
Any ideas?
Without a reproducible example we are left guessing what goes wrong, but the error suggests that the matrix does not contain numbers but (probably) characters. Does this work:
and what is the output of:
(probably
FALSE).edit:
Your edit shows that the matrix contains characters, not numerics. It may be that in the text file the rownames are included as an additional column, probably the first one. In that case:
reads the first column as the rownames. So the problem is most likely in
read.table, not in the conversion to a matrix.