Place the Y axis to the left of the heatmap?

How to make a heatmap with Y axis labels on the left? It seems that by default it is right. Do I need to create a custom axis using axis() ?

+8
r graphics heatmap
source share
1 answer

In the heatmap function, the heatmap positions are hardcoded. But it would be very easy to change only one number to place it on the other side. Type β€œHeatmap” on the console and change the first argument from 4 to 2 in the second axis() call.

All that I changed was:

 axis(2, iy, labels = labRow, las = 2, line = -0.5, tick = 0, # the 2 used to be 4 cex.axis = cexRow) 

It is still necessary to make changes to the fields for the switch. Changing the current value from 0 to 5 seemed to create enough space in the example in which I was playing from the help page:

 ... par(mar = c(margins[1L], 5, 0, margins[2L])) 

This was my test case:

 x <- as.matrix(mtcars) rc <- rainbow(nrow(x), start=0, end=.3) cc <- rainbow(ncol(x), start=0, end=.3) utils::str(hv) # the two re-ordering index vectors ## no dendrogram (nor color strip) heatmap.new(x, Colv = NA, Rowv=NA, col = cm.colors(256), scale="column", margins=c(5,2), xlab = "specification variables", ylab= "Car Models", main = "heatmap(<Mtcars data>, ..., scale = \"column\")") 
+9
source share

All Articles