如何调整热图以显示所有内容?

How can I adjust the heatmap to show everything?

我的热图将元素标签剪掉了,我根本不想让它们显示在底部。我该如何调整它以使其适合所有内容?此外,密钥占用了太多 space,但当我使其小于 1 时,密钥和标题就会消失。

heatmap.2( x=correlation_mat,
           dendrogram="column",
           keysize = 1,
           key.title = NA,
           key.ylab = NA,
           density.info = "none",
           trace = "none",
           Colv = "Rowv",
           scale = "none",
           col = rev(colorRampPalette(brewer.pal(10, "RdBu"))(256)),
           main = "Correlations of Thickness")

为此您需要 gplots 和 RColorBrewer 库。

您可以使用带有两个值的附加 margins 参数来扩大页边距。

以下示例使用随机数据:

library("gplots")
library("RColorBrewer")

## sample data
x <- matrix(rnorm(1000), nrow=10)

## random lables
dimnames(x) <- list(
  replicate(10, paste(sample(letters, 10, replace=TRUE), collapse="")),
  replicate(100, paste(sample(letters, 10, replace=TRUE), collapse=""))
)

correlation_mat <- cor(x)

heatmap.2(x=correlation_mat,
          dendrogram="column",
          keysize = 1,
          key.title = NA,
          key.ylab = NA,
          density.info = "none",
          trace = "none",
          Colv = "Rowv",
          scale = "none",
          col = rev(colorRampPalette(brewer.pal(10, "RdBu"))(256)),
          main = "Correlations of Thickness",
          margins = c(8, 8))

完全删除底部标签margins = c(1, 8)对我有用。