Heatmap making via Complexheatmap package
0
1
Entering edit mode
4.4 years ago
citronxu ▴ 20

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.

R heatmap • 2.7k views
ADD COMMENT
0
Entering edit mode

Can you post the first few lines of your matrix after calling as.matrix on it?

ADD REPLY
0
Entering edit mode

yeah, sure.

enter image description here

ADD REPLY
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

Actually ComplexHeatmap has no problem with NAs and even has a plotting param, na_col, for NA-specific coloring. I routinely plot heatmaps with NAs in my input matrix.

Not sure what @OP's original issue was but wanted to clarify that the NAs 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...

ADD REPLY
0
Entering edit mode

Thank you, but I think that it will still return an error if correlation distance is used.

ADD REPLY

Login before adding your answer.

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