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) 
heatmap.2(as.matrix(df), Rowv = T, Colv = FALSE, dendrogram = "row", #scale = "row", col = col, density.info = "none", trace = "none", margins = c(7, 15) )

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 enter image description here

I'd appreciate your help with this.


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

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).

| improve this answer | |

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.