<p>Make the image itself bigger (e.g., <code>png("S7.png", width=1000, height=1000)</code>).</p>

<p>Having said that, rethink the utility of having the labels there. Are you really going to go through and look at them if you have hundreds of lines? Probably not.</p>

CC BY-SA 4.0
2018-07-22T18:52:15.193Z
2018-07-22T18:52:15.193Z
Devon Ryan
<p><code>heatmap.2</code> is very configurable, and has options to adjust the things you want to fix:</p>

<p><code>cexRow</code>: changes the size of the row label font. </p>

<p><code>keysize</code>: numeric value indicating the size of the key.</p>

<p>The size of the key is also affected by the layout of the plot. <code>heatmap.2</code> splits your plotting device into 4 panes (see the picture below), and you can control the size of the key partly by controlling the size and layout of these 4 panes. </p>

<p><a href="https://i.sstatic.net/QT5Yc.png" rel="noreferrer"><img src="https://i.sstatic.net/QT5Yc.png" alt="enter image description here"></a></p>

<p>The layout and scale of these panes can be controlled using the <code>lmat</code>, <code>lwid</code> and <code>lhei</code> arguments. For example, in your case, because you're not displaying the column dendrogram in your plot, you could set the height of the first row of the layout to be smaller, which would reduce the size of the colour key: <code>lhei=c(2, 10)</code> (this is just an example, you'd need to experiment to find values which worked well for your specific heatmap).</p>

CC BY-SA 4.0
2018-07-23T10:31:11.520Z
2018-07-23T10:31:11.520Z
sjcockell
<p>I have an expression data matrix (120X15; 15 samples and 120 genes), my heatmap looks blurred and raw names (gene names) looks very small and can not read. How can I improve my scripts?</p>
<p>Here is the example data</p>
<pre><code>df&lt;-structure(list(X_T0 = c(1.32606106633333, 0.222768019,  1.27419565966667, 0.293489379),
X_T1 = c(1.499956424, 0.293117217, 1.11955345266667, 0.324453864666667),
X_T2 = c(1.118528738, 0.548228048, 0.936319105, 0.846378238666667), 
X_T3 = c(1.025082136, 0.841192647333333, 0.957743318666667, 1.10810667833333),
Y_T0 = c(0.424537206666667, 3.144197864, 1.01435004766667, 2.195831453),
Y_T1 = c(0.723243112666667, 0.576764958333333, 0.604810037, 0.896297411666667),
Y_T2 = c(0.335509156333333, 1.32037215366667, 1.209961935, 0.290895345333333),
Y_T3 = c(0.328275209, 1.15039119233333, 1.409758678, 0.0922298696666667),
Z_T0 = c(0.788329993666667, 1.03539976366667, 1.10523299, 0.885098106666667), 
Z_T1 = c(1.125292329, 1.00032109266667, 0.877359233, 1.385935293), 
Z_T2 = c(2.357924224, 0.740699933666667, 0.585095342, 1.98251017733333),
Z_T3 = c(0.678921448, 0.687992671666667, 1.005347728, 1.05829030233333)), row.names = c(&quot;AA&quot;, &quot;PQ&quot;, &quot;UBQ&quot;, &quot;XY&quot;), class = &quot;data.frame&quot;)
</code></pre>
<p>Script being used</p>
<pre><code>col &lt;- colorRampPalette(c(&quot;red&quot;,&quot;yellow&quot;,&quot;darkgreen&quot;))(30) 
png(&quot;S7.png&quot;)
heatmap.2(as.matrix(df), Rowv = T, Colv = FALSE, dendrogram = &quot;row&quot;, #scale = &quot;row&quot;, col = col, density.info = &quot;none&quot;, trace = &quot;none&quot;, margins = c(7, 15) )
dev.off()
</code></pre>
<p>For sample data, this script generates perfect heatmap, but when I have more raw data(genes), this problem comes
I've tried to change these margins = c(7, 15) value, doesn't work well and not sure how to proceed.
Also, I want to reduce the height of the color key
<a href="https://i.sstatic.net/ogzDU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ogzDU.png" alt="enter image description here" /></a></p>
<p>I'd appreciate your help with this.</p>

<r><rna-seq><proteins><clustering>
How to scale the size of heat map and row names font size?
# How to scale the size of heat map and row names font size?

(Asked by: username_0 on 2018-07-22)

I have an expression data matrix (120X15; 15 samples and 120 genes), my heatmap looks blurred and raw names (gene names) looks very small and can not read. How can I improve my scripts?
Here is the example data
df<-structure(list(X_T0 = c(1.32606106633333, 0.222768019,  1.27419565966667, 0.293489379),
X_T1 = c(1.499956424, 0.293117217, 1.11955345266667, 0.324453864666667),
X_T2 = c(1.118528738, 0.548228048, 0.936319105, 0.846378238666667), 
X_T3 = c(1.025082136, 0.841192647333333, 0.957743318666667, 1.10810667833333),
Y_T0 = c(0.424537206666667, 3.144197864, 1.01435004766667, 2.195831453),
Y_T1 = c(0.723243112666667, 0.576764958333333, 0.604810037, 0.896297411666667),
Y_T2 = c(0.335509156333333, 1.32037215366667, 1.209961935, 0.290895345333333),
Y_T3 = c(0.328275209, 1.15039119233333, 1.409758678, 0.0922298696666667),
Z_T0 = c(0.788329993666667, 1.03539976366667, 1.10523299, 0.885098106666667), 
Z_T1 = c(1.125292329, 1.00032109266667, 0.877359233, 1.385935293), 
Z_T2 = c(2.357924224, 0.740699933666667, 0.585095342, 1.98251017733333),
Z_T3 = c(0.678921448, 0.687992671666667, 1.005347728, 1.05829030233333)), row.names = c("AA", "PQ", "UBQ", "XY"), class = "data.frame")

Script being used
col <- colorRampPalette(c("red","yellow","darkgreen"))(30) 
png("S7.png")
heatmap.2(as.matrix(df), Rowv = T, Colv = FALSE, dendrogram = "row", #scale = "row", col = col, density.info = "none", trace = "none", margins = c(7, 15) )
dev.off()

For sample data, this script generates perfect heatmap, but when I have more raw data(genes), this problem comes
I've tried to change these margins = c(7, 15) value, doesn't work well and not sure how to proceed.
Also, I want to reduce the height of the color key

I'd appreciate your help with this.

**Tags:** r, rna-seq, proteins, clustering

---

## 2 answers

### Answer by username_2 on 2018-07-23. Score: 5 | Accepted answer

`heatmap.2` is very configurable, and has options to adjust the things you want to fix:

`cexRow`: changes the size of the row label font.

`keysize`: numeric value indicating the size of the key.

The size of the key is also affected by the layout of the plot. `heatmap.2` splits your plotting device into 4 panes (see the picture below), and you can control the size of the key partly by controlling the size and layout of these 4 panes.

[![enter image description here](https://i.sstatic.net/QT5Yc.png)](https://i.sstatic.net/QT5Yc.png)

The layout and scale of these panes can be controlled using the `lmat`, `lwid` and `lhei` arguments. For example, in your case, because you're not displaying the column dendrogram in your plot, you could set the height of the first row of the layout to be smaller, which would reduce the size of the colour key: `lhei=c(2, 10)` (this is just an example, you'd need to experiment to find values which worked well for your specific heatmap).


---

### Answer by username_1 on 2018-07-22. Score: 3

Make the image itself bigger (e.g., `png("S7.png", width=1000, height=1000)`).

Having said that, rethink the utility of having the labels there. Are you really going to go through and look at them if you have hundreds of lines? Probably not.


---

