Search code examples
rheatmapgplots

R: Changing the size of a heatmap.2 rowname column


I used the following code:

library("gplots")
heatmap.2(assay(vsd)[ens_union,], trace = "none", density.info = "none")

To produce the following heatmap:

heatmap.2: row labels cut-off

As you can see, the row labels have been cut-off (the first one should, for instance, be ENSMUSG00000000088, but only ENSMUSG0 is displayed). How can I re-size the plot to include the whole labels?


Solution

  • Just add the margins argument

    library("gplots")
    
    # generate some example data
    data <- as.matrix(mtcars)
    
    # make ridiculously long names
    long.names     <- paste("ENSMUSG000000000", rownames(mtcars))
    rownames(data) <- long.names
    
    # GO!
    heatmap.2(data, trace = "none", density.info = "none", 
              margins = c(8, 16)) 
    

    Don't forget you can also change the font size if you like with cexRow