Graph of heat map with its own color for some values ​​in r

Here are the data:

set.seed(123) mat <- matrix(rnorm(5000, 0.5, 0.2), 50) heatmap (mat) 

enter image description here

 mat[mat > 0.05] <- NA heatmap (mat) Error in hclustfun(distfun(x)) : NA/NaN/Inf in foreign function call (arg 11) 

Replacing it with other values ​​(it can optionally help), but it can deceive readers, because it will choose a color from the same scale, which is wrong. Therefore, I want to set a completely different color for those values ​​that exceed 0.05.

 mat[mat > 0.05] <- 0.1 heatmap (mat) 

enter image description here

+4
source share
1 answer

may be...

 library(gplots) set.seed(123) mat <- matrix(rnorm(5000, 0.5, 0.2), 50) heatmap.2(mat, breaks=c(-1,0.02,0.05,1), col=c("yellow", "red", "blue"), # aiming for >0.05 is blue dendrogram="both", trace="none") 

Mostly play with col= and breaks=

as follows:

enter image description here

+4
source

Source: https://habr.com/ru/post/1412261/


All Articles