简体   繁体   English

R gplots中heatmap.2中的错误

[英]Error in heatmap.2 in R gplots

I am using heatmap.2 in gplots to create heatmaps in R. My code used to work fine for creating a heatmap. 我在gplots中使用heatmap.2在R中创建热图。我的代码过去可以很好地用于创建热图。 But recently it started throwing errors. 但是最近它开始引发错误。 I am not sure why it is happening. 我不确定为什么会这样。

# 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()

Now it throws error: 现在抛出错误:

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

This code plots the heatmap but not the color key . 此代码绘制热图,但绘制颜色键

I had this same problem using heatmap.2. 我在使用热图2时遇到了同样的问题。 It seems to result from having one or more zero values in the vector returned by diff(breaks). 这似乎是由于diff(breaks)返回的向量中具有一个或多个零值而导致的。 The 'by' call fails when min(diff(breaks)) is zero. 当min(diff(breaks))为零时,“ by”调用失败。 I changed my break points to be non-overlapping and the color key was able to be displayed. 我将断点更改为不重叠,并且可以显示颜色键。

Initially I had: 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.033,0.066,length = 26),seq(0.066,0.1,length = 25))

I changed this to: breaks=c(seq(0,0.033,length=25),seq(0.0331,0.066,length=26),seq(0.0661,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))

It seems to have resolved the issue and allows me to use the color key again. 看来已解决了问题,并允许我再次使用颜色键。

I am having the same issue. 我有同样的问题。 I was able to produce a plot with a key, but not with as much control as I'd like: 我能够用一个键来生成一个图,但是并没有我想要的那样多的控制:

I removed the "breaks" option entirely and used col=redblue(64) and that produced a two-colored heatmap with a key. 我完全删除了“ breaks”选项,并使用了col = redblue(64),这产生了带有键的双色热图。

I had the following problem, getting the above example: 我遇到了以下问题,得到了上面的例子:

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")    

Generates this heatmap: 生成此热图:

starting heatmap 起始热图

But if I introduce a negative number in the matrix and I modify the breaks in the vector to account for this negative number, ie 但是,如果我在矩阵中引入一个负数,然后修改向量的中断以解决这个负数,即

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")  

The key completely fails: 密钥完全失败:

failed heatmap 失败的热图

Following this answer adding simkey=FALSE solves the issue, and it seems to work in this example: 此答案之后,添加simkey=FALSE解决此问题,并且在此示例中似乎可行:

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

As you can see: 如你看到的:

correct heatmap 正确的热图

Using the same break points (in my example two times 10 and 40 respectively) gives this error, ie: 使用相同的断点(在我的示例中分别为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))

brings this error, while 带来这个错误,而

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))

solves this error for: 解决此错误的原因:

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.

相关问题 热图中的错误.2(gplots) - Error in heatmap.2 (gplots) R heatmap.2(图)访问树状图数据 - R heatmap.2 (gplots) access dendogram data R:居中 heatmap.2 键(gplots 包) - R: Centering heatmap.2 key (gplots package) R - gplots - 当key = FALSE时删除heatmap.2中的空格 - R - gplots - Removing white space in heatmap.2 when key=FALSE R中的新gplots更新无法在heatmap.2中找到函数distfun - New gplots update in R cannot find function distfun in heatmap.2 在R heatmap中移动颜色键.2(gplots包的功能) - Moving color key in R heatmap.2 (function of gplots package) gplots中的R heatmap.2-通过树状图时无法复制该图: - R heatmap.2 in gplots - can't replicate the plot when dendograms are passed: 在`R`中的`gplots`中,我们如何调整`heatmap.2`函数中x-label刻度的位置? - In `gplots` in `R`, how can we adjust the position of the x-label ticks in the `heatmap.2` function? R gplots heatmap.2-使用breaks参数时密钥不稳定(警告:未排序的“ breaks”将在使用前进行排序) - R gplots heatmap.2 - key is unstable using breaks parameter (warning: unsorted 'breaks' will be sorted before use) 调整R中heatmap.2函数(gplots)的基础代码,以更改trace参数 - Adjust underlying code for the heatmap.2 function (gplots) in R, to change the trace argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM