配件缺失从情节,这则重新出现,并覆盖整个小区当得救吗? (R,Heatmap.2)(Parts

2019-10-28 17:28发布

我使用heatmap.2创建一个情节,然而,缺少一个关键和标题被保存到我的源文件夹的初始情节。

当我再运行dev.off()命令,密钥和标题,然后用于覆盖原来的图形?

举例来说,我会产生这样一个情节:

这是远远不够完善。 但后来当我运行dev.off()关闭设备(否则其他错误的主机随之而来):

什么,你在上面看到的是一个非常扭曲的关键,我的“XYZ”称号。

为什么地球上是创建两个文件,首先在一个与我的基质,然后用​​含我翻转键,我的标题第二个文件覆盖吗? 我不能按照逻辑。

我已经更新我的操作系统,我的R,RStudio,我的所有包的版本和unistalled RStudio。 似乎没有任何帮助。

如果您想尝试,并在这里复制我的错误是例如矩阵:

structure(c(1, 4, 5, 3, 3, 4, 6, 1, 7, 5, 5, 4, 4, 8, 1, 3, 9, 
2, 2, 9, 3, 1, 3, 4, 4, 5, 5, 5, 1, 4, 4, 3, 3, 3, 9, 1), .Dim = c(6L, 
6L))

这是我用绘制我的例子中数据的脚本。 您需要提供SourceDir,并确保你的矩阵分配给名为“黑客帝国”。

if (!require("gplots")) {
  install.packages("gplots", dependencies = TRUE)
  library(gplots)
}
if (!require("RColorBrewer")) {
  install.packages("RColorBrewer", dependencies = TRUE)
  library(RColorBrewer)
}

my_palette <- colorRampPalette(c("snow", "yellow", "darkorange", "red"))(n = 399)


transition
    col_breaks = c(seq(0,1,length=100),    #white 'snow'
                   seq(2,4,length=100), # for yellow
                   seq(5,7,length=100), # for orange 'darkorange'
                   seq(8,9,length=100))    # for red


png(paste(SourceDir, "Heatmap_Test.png"),      
    width = 5*1000,       
    height = 5*1000,
    res = 300,           
    pointsize =15)

heatmap.2(Matrix,
          main =  paste("XYZ"), 
          notecol="black",
          key = "true" ,
          colsep = c(3, 6, 9),
          rowsep = c(3, 6, 9),
          labCol = NULL,
          labRow = NULL,
          sepcolor="white",
          sepwidth=c(0.08,0.08),
          density.info="none",  
          trace="none",         
          margins=c(1,1),     
          col=my_palette,       
          breaks=col_breaks,    
          dendrogram="none",     
          RowSideColors = c(rep("blue", 3), rep("orange", 3)),
          ColSideColors = c(rep("blue", 3), rep("orange", 3)),
          srtCol = 0 ,        
          asp = 1 ,         
          adjCol = c(NA, 0) , 
          adjRow = c(0, NA) , 
          #keysize =  2 ,  
          Colv = FALSE ,      
          Rowv =  FALSE ,    
          key.xlab = paste("Correlation") , 
          cexRow = (1.8) , 
          cexCol = (1.8) , 
          notecex = (1.5) , 
          lmat = rbind(c(0,0,0,0), c(0,0,2,0),c(0,1,3,0),c(0,0,0,0)) , 
          #par(ColSideColors = c(2,2)),
          lhei = c(1, 1, 3, 1) , 
          lwid = c(1, 1, 3, 1)) 

dev.off()

我真的很感激任何洞察到这一问题。

Answer 1:

相信这是由于这样的事实,我已不仅仅是元件1至4以上,作为有色行我已经加入算作一个必须设置在显示矩阵的附加元件。

因此:

mat = rbind(c(0,0,0,0), c(0,0,2,0),c(0,1,3,0),c(0,0,0,0)) , 
lhei = c(1, 1, 3, 1) , 
lwid = c(1, 1, 3, 1))

不再切黄油。 无事生非,我终于设法得到如下的布局工作(我的实际数据,而不是我的示例数据)。

lmat = rbind(c(0,4,5,0), c(0,0,2,0),c(0,1,3,0),c(0,0,6,0)) , 
lhei = c(0.4, 0.16, 3, 0.4) , # Alter dimensions of display array cell heighs
lwid = c(0.4, 0.16, 3, 0.4),

注意元件5和6的夹杂物。

所以,我最后的命令如下(请注意,还会有很多其他的变化,但真正的进展发生过一次我在加5和6):

png(paste(SourceDir, "XYZ.png"),         
    width = 5*1500,        
    height = 5*1500,
    res = 300,            # 300 pixels per inch
    pointsize =30)        

heatmap.2(CombinedMtx,
          main =  paste("XYZ"), # heat map title
          notecol="black",
          key = "true" ,# change font color of cell labels to black
          colsep = c(6, 12, 18),
          labCol = c(" "," "," ", "XX"," "," "," "," "," ", "YY"," "," "," "," "," ", "ZZ"," "," "," "," "," ", "QQ"),
          rowsep = c(6, 12, 18),
          labRow = c(" "," "," ", "XX"," "," "," "," "," ", "YY"," "," "," "," "," ", "ZZ"," "," "," "," "," ", "QQ"),
          sepcolor="white",
          sepwidth=c(0.08,0.08),
          density.info="none",  
          trace="none",         
          margins=c(1,1),     
          col=my_palette,      
          breaks=col_breaks,   
          dendrogram="none",     
          RowSideColors = c(rep("#deebf7", 6), rep("#1c9099", 6), rep("#addd8e", 6), rep("#fee391", 6)),
          ColSideColors = c(rep("#deebf7", 6), rep("#1c9099", 6), rep("#addd8e", 6), rep("#fee391", 6)),
          srtCol = 0 ,        
          asp = 1 ,         
          adjCol = c(1.5, -61.5) , 
          adjRow = c(0, -1.38), 
          offsetRow = (-59.5),
          keysize =  2 ,  
          Colv = FALSE ,     
          Rowv =  FALSE ,    
          key.xlab = NA , 
          key.ylab = NULL ,
          key.title = NA ,
          cexRow = (1.6) , 
          cexCol = (1.6) , 
          notecex = (1.5) , 
          cex.main = (20),
          lmat = rbind(c(0,4,5,0), c(0,0,2,0),c(0,1,3,0),c(0,0,6,0)) , 
          #par(ColSideColors = c(2,2)),
          lhei = c(0.4, 0.16, 3, 0.4) , # Alter dimensions of display array cell heighs
          lwid = c(0.4, 0.16, 3, 0.4),
          symkey = any(0.5 < 0, na.rm=FALSE) || col_breaks,
          key.par=list(mar=c(3.5,0, 1.8,0) )  #tweak specific key paramters
)
dev.off() 

另外,如果你不通过创建PNG每次启动和每次使用ENF dev.off()将无法正常工作。 我相信,这可能也有我的困惑了贡献,并绘制热图后潜在的,正在拟订的一些元素,一旦dev.off()命令运行,从而导致热图被覆盖。

这(与我的矩阵)创建此图像。

我所做的是我的标签块的真正gammy方式,但直到我可以工作如何获得ComplexHeatmap正常工作,我就会一直使用这样与黑客Heatmap.2



文章来源: Parts Missing From Plot, That then Reappear and Overwrite The Entire Plot When Saved? (R, Heatmap.2)