我有以下代码:
my_palette <- colorRampPalette(rev(RColorBrewer::brewer.pal(11, "RdBu")))(n = 50)
par(mar = c(7, 4, 4, 2) + 0.1)
gplots::heatmap.2(as.matrix(mtcars),
Colv = TRUE,
Rowv = TRUE,
col = my_palette,
density.info = "none",
key = TRUE,
scale = "none",
ylab = "Y_LABEL",
xlab = "X_LABEL",
trace = "none",
margins = c(12, 8))
它产生了这个情节:
请注意,颜色键中最红色的颜色对应于mtcars
的最大值472。
是否可以将最大值增加到1000,以使热图中的颜色范围从0到1000?
采用这种方案,值472的单元格将比红色甚至蓝色或白色的单元格少得多。
答案 0 :(得分:1)
一种方法是手动指定用于颜色的breaks
(请参见最后一行):
# NOTE: starting from R v3.6.0 base has palettes, so you don't need RColorBrewer
my_palette <- hcl.colors(64, palette="RdBu", rev=TRUE)
par(mar = c(7, 4, 4, 2) + 0.1)
gplots::heatmap.2(as.matrix(mtcars),
Colv = TRUE,
Rowv = TRUE,
col = my_palette,
density.info = "none",
key = TRUE,
scale = "none",
ylab = "Y_LABEL",
xlab = "X_LABEL",
trace = "none",
margins = c(12, 8),
breaks=seq(0,1000,1000/length(my_palette)))