在R中,如何开发多图热图。2成功显示关键标签的图

时间:2018-11-15 19:15:44

标签: r heatmap axis-labels margins

我正在尝试开发保存到pdf的多图热图。我取得了一些成功,但是轴标签被砍掉了。子图标题也是可取的,但标签又被切碎了。

这是我的可复制代码:

library(gridExtra)
library(grid)
library(gridGraphics)
library(gplots)


Col  = colorRampPalette(c("red","orange","yellow", "white"))

grab_grob <- function(){
  grid.echo()
  grid.grab()
}
par(cex.main=0.1, mar = c(1,1,1,1) )
#data<-read.table("heatmap.input.matrix.data.txt")
lmat = rbind(c(2,3),c(4,1),c(4,1))
lwid = c(2.5,4)
lhei = c(0.5,4,3)
labRowvec <- c(rep(NULL, dim(matrix(runif(1000, 1,10),ncol=50))[1]))
labColvec <- c(rep(NULL, dim(matrix(runif(1000, 1,10),ncol=50))[2]))

gl <- lapply(1:12, function(i){
  heatmap.2(matrix(runif(1000, 1,10),ncol=50), dendrogram = "none",offsetRow=-0.5, offsetCol=-1,srtCol=0, density="density",
            lmat =lmat,lhei = lhei,lwid = lwid, xlab="", ylab = "",labRow = labRowvec,labCol = labColvec,
            trace = "none", cexRow = 0.2, cexCol = 0.2, margins = c(0.5,2), scale = "row",Colv = FALSE,Rowv = FALSE,
            col = Col,key.title =   paste0(i,")"),key.xlab = "year",key.ylab = NA,
            keysize = 1, key.par=list(mar=c(1,1, 1, 1)))

  grab_grob()
})

grid.newpage()
library(gridExtra)
# margin = theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "cm"))
# grid.arrange(grobs = lapply(gl, "+", margin),ncol=2,clip=TRUE)


g = arrangeGrob(grobs = gl, ncol=2,clip=TRUE)
ggsave(file="whatever.pdf", g)

有人可以帮我维护轴标签并添加子图标题吗?

谢谢。

以下是代码生成的内容: enter image description here

0 个答案:

没有答案