【问题标题】:How to increase the max values of color range in heatmap.2()如何增加 heatmap.2() 中颜色范围的最大值
【发布时间】:2019-07-24 09:42:57
【问题描述】:

我有以下代码:

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 的单元格将少得多红色,甚至是蓝色或白色。

【问题讨论】:

    标签: r plot heatmap


    【解决方案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)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-28
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      相关资源
      最近更新 更多