繁体   English   中英

尝试使用heatmap.2绘制时出现错误(与颜色有关)

[英]Error (relating to colours) when trying to plot using heatmap.2

我正在尝试使用heatmap.2创建图,但我不断收到错误,该错误must have one more break than colour

如果有兴趣,我会改编此章的代码: https : //sebastianraschka.com/Articles/heatmaps_in_r.html

这是有问题的代码部分:

# creates a own color palette 
my_palette <- colorRampPalette(c("snow", "yellow", "darkorange", "red"))(n = 299)

# (optional) defines the color breaks manually for a "skewed" color transition
col_breaks = c(seq(0,0.15,length=100), #white
               seq(0.16,0.29,length=100), # for yellow
               seq(0.3,0.5,length=100), # for orange
               seq(0.51,1,length=100))    # for red

现在让我真正感到困惑的是,这行得通:

# creates a own color palette 
my_palette <- colorRampPalette(c("snow", "yellow", "red"))(n = 299)


# (optional) defines the color breaks manually for a "skewed" color transition
col_breaks = c(seq(0,0.29,length=100),  #white
                  seq(0.3,0.5,length=100), # for yellow
                  seq(0.51,1,length=100))  # for red

在我对为什么再次失败之前感到非常困惑之前,我似乎已经正确地修改了原始代码一次。

解决方案是:

# creates a own color palette 
my_palette <- colorRampPalette(c("snow", "yellow", "darkorange", "red"))(n = 399)

# (optional) defines the color breaks manually for a "skewed" color transition
col_breaks = c(seq(0,0.15,length=100), #white
               seq(0.16,0.29,length=100), # for yellow
               seq(0.3,0.5,length=100), # for orange
               seq(0.51,1,length=100))    # for red

唯一相关的更改是n=399 ,因为您定义了长度为400的col_breaks。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM