将Y轴放在热图的左侧?

时间:2011-09-02 17:42:28

标签: r graphics heatmap

如何使用左侧的Y轴标签制作热图?它似乎默认为正确。我是否需要使用axis()制作自定义轴?

1 个答案:

答案 0 :(得分:9)

heatmap功能中,轴的位置是硬编码的。但是只更改一个数字就可以很容易地将它定位在另一侧。在控制台输入“heatmap”,并在第二次axis()调用中将第一个参数从4更改为2。

我改变的是:

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

仍需要更改边距以适应开关。将当前值0更改为5似乎在我从帮助页面播放的示例中创建了足够的空间:

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

这是我的测试用例:

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\")")