In R, how to develop a multiplot heatmap.2 figure showing key labels successfully










1















I'm trying to develop a multiplot heatmap.2 saved to a pdf. I'm having some success but the axis labels are getting chopped off. Subplot titles are also desirable but again the labels are getting chopped.



Here's my reproducible code:



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)


Can someone help me maintain the axis labels and add a subplot title?



thanks.



Here's what the code generates:
enter image description here










share|improve this question




























    1















    I'm trying to develop a multiplot heatmap.2 saved to a pdf. I'm having some success but the axis labels are getting chopped off. Subplot titles are also desirable but again the labels are getting chopped.



    Here's my reproducible code:



    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)


    Can someone help me maintain the axis labels and add a subplot title?



    thanks.



    Here's what the code generates:
    enter image description here










    share|improve this question


























      1












      1








      1


      2






      I'm trying to develop a multiplot heatmap.2 saved to a pdf. I'm having some success but the axis labels are getting chopped off. Subplot titles are also desirable but again the labels are getting chopped.



      Here's my reproducible code:



      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)


      Can someone help me maintain the axis labels and add a subplot title?



      thanks.



      Here's what the code generates:
      enter image description here










      share|improve this question
















      I'm trying to develop a multiplot heatmap.2 saved to a pdf. I'm having some success but the axis labels are getting chopped off. Subplot titles are also desirable but again the labels are getting chopped.



      Here's my reproducible code:



      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)


      Can someone help me maintain the axis labels and add a subplot title?



      thanks.



      Here's what the code generates:
      enter image description here







      r heatmap axis-labels margins






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 19:52







      Geoff

















      asked Nov 15 '18 at 19:15









      GeoffGeoff

      7919




      7919






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326480%2fin-r-how-to-develop-a-multiplot-heatmap-2-figure-showing-key-labels-successfull%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326480%2fin-r-how-to-develop-a-multiplot-heatmap-2-figure-showing-key-labels-successfull%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Museum of Modern and Contemporary Art of Trento and Rovereto