gpt4 book ai didi

r - R gplots 中的 heatmap.2 错误

转载 作者:行者123 更新时间:2023-12-05 02:22:10 32 4
gpt4 key购买 nike

我在 gplots 中使用 heatmap.2 在 R 中创建热图。我的代码过去可以很好地创建热图。但最近它开始抛出错误。我不确定为什么会这样。

# Matrix to feed heatmap.2
mat = as.matrix(sort_pkmat)
# color palette for diff. colors
my_palette <- colorRampPalette(c("white","red","red4"))(n = 299)
# color breaks for range
col_breaks = c(seq(0,40,length=100),
seq(40,60,length=100),
seq(60,90,length=100))

path1 = paste(path,name,'.png', sep = '')
print(path1)
png(path1,
width = 10*300, # 5 x 300 pixels
height = 8*300,
res = 300, # 300 pixels per inch
pointsize = 8)


heatmap.2(mat,
#cellnote = mat, # same data set for cell labels
main = "Tag_density_HeatMap", # heat map title
xlab = "Peaks",
ylab = "Chip_samples",
labRow = FALSE,
labCol = FALSE,
cexRow = 0.7, # Changes the size of col and row font size
cexCol = 0.2,
notecol="black", # change font color of cell labels to black
density.info="none", # turns off density plot inside color legend
trace="none", # turns off trace lines inside the heat map
margins =c(3,5), # widens margins around plot
col=my_palette, # use on color palette defined earlier
breaks=col_breaks, # enable color transition at specified limits
dendrogram="none", # only draw a row dendrogram
Colv= FALSE, #cluster column
Rowv = FALSE,
#keysize = 1
)
dev.off()

现在它抛出错误:

Error in seq.default(min.raw, max.raw, by = min(diff(breaks)/4)) : 
invalid (to - from)/by in seq(.)
> dev.off()
null device
1

此代码绘制热图,但不绘制颜色键

最佳答案

我在使用 heatmap.2 时遇到了同样的问题。这似乎是 diff(breaks) 返回的向量中有一个或多个零值的结果。当 min(diff(breaks)) 为零时,'by' 调用失败。我将断点更改为不重叠,并且能够显示颜色键。

最初我有:breaks=c(seq(0,0.033,length=25),seq(0.033,0.066,length=26),seq(0.066,0.1,length=25))

我将其更改为:breaks=c(seq(0,0.033,length=25),seq(0.0331,0.066,length=26),seq(0.0661,0.1,length=25))

它似乎已经解决了问题并允许我再次使用颜色键。

关于r - R gplots 中的 heatmap.2 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30527885/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com