簡體   English   中英

R gplots中heatmap.2中的錯誤

[英]Error in heatmap.2 in R gplots

我在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 

此代碼繪制熱圖,但繪制顏色鍵

我在使用熱圖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))

看來已解決了問題,並允許我再次使用顏色鍵。

我有同樣的問題。 我能夠用一個鍵來生成一個圖,但是並沒有我想要的那樣多的控制:

我完全刪除了“ breaks”選項,並使用了col = redblue(64),這產生了帶有鍵的雙色熱圖。

我遇到了以下問題,得到了上面的例子:

x = matrix(runif(100^2, min=0, max=100), ncol=100)
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 99) # 100 percent
col_breaks = c(seq(0,10,length=40),  
             seq(11,40,length=30),              
             seq(41,100,length=30))
hm <- heatmap.2(x,
           col=my_palette,       
           breaks=col_breaks,
           dendrogram="none",
           Colv="NA", Rowv="NA")    

生成此熱圖:

起始熱圖

但是,如果我在矩陣中引入一個負數,然后修改向量的中斷以解決這個負數,即

x = matrix(runif(100^2, min=-1, max=100), ncol=100)
col_breaks = c(seq(-1,10,length=40),  
             seq(11,40,length=30),              
             seq(41,100,length=30))
hm <- heatmap.2(x,
           col=my_palette,       
           breaks=col_breaks,
           dendrogram="none",
           Colv="NA", Rowv="NA")  

密鑰完全失敗:

失敗的熱圖

此答案之后,添加simkey=FALSE解決此問題,並且在此示例中似乎可行:

hm <- heatmap.2(x,
           col=my_palette,       
           breaks=col_breaks,
           symkey=FALSE,
           dendrogram="none",
           Colv="NA", Rowv="NA")

如你看到的:

正確的熱圖

使用相同的斷點(在我的示例中分別為10和40兩次)會產生此錯誤,即:

my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 99) # 100 percent


col_breaks = c(seq(0,10,length=40),  
                 seq(10,40,length=30),              
                 seq(40,100,length=30))

帶來這個錯誤,而

my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 99) # 100 percent



col_breaks = c(seq(0,10,length=40),  
                 seq(11,40,length=30),              
                 seq(41,100,length=30))

解決此錯誤的原因:

x = matrix(runif(100^2, min=0, max=100), ncol=100)
hm <- heatmap.2(x,
               col=my_palette,       
               breaks=col_breaks,
               dendrogram="none",
               Colv="NA", Rowv="NA")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM