Hello there,
Recently I've changed into MacOS and encountered some problems in Rstudio using. The thing is, when I plotted my data into heat map using ComplexHeatmap package in R studio, following the commands
mat <- read.table("xxx.csv", header = T, na.string = "-", sep = ";") #read the table from a .csv file
rownames(mat) = mat$gene # set the first 'gene' column as row names
mat <- data.matrix(mat[-1]) # basically changing into matrix which could be used
after these commands, the problem is that all values in my table are transformed from numeric into integers automatically... I figure that it may lies on the properties of all of my data in the original csv file are somehow inappropriate, but I don't know how should I change it... also with the same commands desired heat map could be build perfectly in windows...
also,I tried another command, replacing 'data.matrix' with 'as.matrix' and it did solve my former problem, but only heat map with discrete pattern, which means each data is represented by one unique colour, could be established. When it comes to plotting my data into a continuous pattern with data shown by continuous colour bar, for which I tended to achieve by following commands:
library(circlize)
col_fun = colorRamps2(c(-2,0,2), c("green", "white", "red"))
Heatmap(mat, col = col_fun)
then came the error info:
Error in x - break2 : non-numeric argument to binary operator In addition: Warning message: In .bincode(x2, breaks, right = TRUE, include.lowest = TRUE) : NAs introduced by coercion
appreciate any advice, many thanks in advance.
Can you post the first few lines of your matrix after calling
as.matrix
on it?yeah, sure.
Well, whatever is the cause of the error, you cannot generate a heatmap with NA values. You will have to remove any gene with NA or impute these values.
Actually
ComplexHeatmap
has no problem withNA
s and even has a plotting param,na_col
, for NA-specific coloring. I routinely plot heatmaps withNA
s in my input matrix.Not sure what @OP's original issue was but wanted to clarify that the
NA
s shouldn't inherently be an issue. Now, if you wanted cluster and split rows or columns via K-means cluster then you'll run into issues...Thank you, but I think that it will still return an error if correlation distance is used.