How do you make a heat map and cluster with NA values?

南笙酒味 提交于 2019-12-05 13:01:42

To get this to work you need to specify the breaks.Note: There needs to be one more break than colors.

library(gplots)

dat <- matrix(2**rnorm(900, sd = 5), ncol=9)
dat[sample(seq_along(dat), size = 180)] <- 0 ##setting some data to 0

my_palette <- colorRampPalette(c("yellow", "orange", "red")) (n=20)
breaks <- seq(min(dat2, na.rm = T), max(dat2, na.rm = T), length.out = 21)

dat2 <- log2(dat+1)
dat2[dat2 == 0] <- NA
heatmap.2(dat2, trace="none", na.color = "black", scale="none", 
          col = my_palette, breaks=breaks)

My two cents about your more general visualization question:

1) All of your data is above 0 so I would recommend using a sequential color map, not a divergent color map. White tends to be viewed as 0, like in this case I see white and automatically thing it is 0.

2) Your current heatmap looks good to me, i.e. well clustered and represented (color map aside). I'm not sure how much "better" it could get or what "better" would look like.

3) If your data has 0's in it I would keep them, so long as they are meaningful. This is very data dependent.

4) You could look into different distance metrics that may treat/weight 0 entries differently.

5) Setting 0s to NA will change the clustering because distances are calculated on complete cases only, by default. Seedist for more info.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!