4

Pheatmap only creates a square plot when legend=FALSE. I have tried using par() to allow more oma() and mar() space without luck. The legend is also really big and i cannot find any documentation on reducing this or changing its position. The first plot doesn't have a dendrogram fitted but this is irrelevant to the sizing issue. The same happens regardless of the clustering. I would appreciate any comments

png(filename="tmpfile.png", width=1500, height=1500, res=500)
pheatmap(res, cluster_rows=FALSE, cluster_cols=FALSE, main="Default_clust", annotation=res2, color = rainbow(n, start=.7, end=.1), show_rownames=FALSE, show_colnames=FALSE, border_col=NA, fontsize=6)
dev.off()

Square plot with no legend plot has legend but is not square

Lel
  • 139
  • 1
  • 2
  • 13

3 Answers3

4

The question about square plot is actually quite relevant for plotting Pearson correlations. I came here hoping for an answer, in the end I came up with a workaround to set the cell width manually, eg:

pheatmap(...,     
cellheight=3, cellwidth = 3)

But I would like a better way.

MonikaP
  • 147
  • 9
3

A hacky way to change the legend size is to set your fontsize. That is, the legend size in pheatmap is proportional to the fontsize. You can then set your row and column label sizes independently (fontsize_row, fontsize_col). The only problem with this method is that of course your annotation labels will also be enlarged or shrunken, but it looks like you're not using them anyway.

Also, pretty sure that your heatmap is square because your png is square.

KeelyD
  • 161
  • 4
  • 3
2

Using the suggested example this is what I get:

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

# Draw heatmaps
pheatmap(test, cluster_row = FALSE, legend_breaks = -1:4, legend=T, legend_labels = c("this is a     really long item", "1e-4", "1e-3", "1e-2", "1e-1", "1"))

Labels and legend are now visible:

enter image description here

The Unfun Cat
  • 29,987
  • 31
  • 114
  • 156
mr.joshuagordon
  • 754
  • 4
  • 8
  • Thanks for this comment. Unfortunately legend breaks is the only difference in this example - and this option does not change the size of my legend but just the breaks. I don't think its to do with writing the file to png as the legend is the same size when I just open it with x11 graphics. – Lel Aug 26 '14 at 03:57