gpt4 book ai didi

r - 使用 pheatmap 时裁剪的列标签

转载 作者:行者123 更新时间:2023-12-03 10:46:16 24 4
gpt4 key购买 nike

我正在使用 绘制热图pheatmap (Documentation)。我正在以一种相当简单的方式绘制一个矩阵:

pheatmap(mat, annotation_col=df, labels_col=rld$Infection_Line, fontsize_row=5, fontsize_col=7) 

我的情节的底部被切断了,所以我看不到底部的列名。它看起来像这样:

enter image description here

请注意,这不是 heatmap.2。

我已经尝试了 this question 的解决方案在 this question ,以及我可以通过谷歌和此功能的文档找到的其他内容。

我尝试使用 par() 和 oma() 以及 cexRow 来增加边距。
margins=(x,y); par(mar=c(1,2,3,4)); par(oma=c(1,2,3,4))  

对剧情没有影响。

我需要这样做,以便在不减小绘图大小的情况下看到这些长列名。我只想拉伸(stretch)底部的边距。

最佳答案

我想详细说明rmf's answer .
关键问题是摆弄 cellwidthcellheight以及 widthheight .前者改变了一个单元格占用了多少像素,后者改变了输出图像的大小。因此,如果您的绘图剪辑超出了图像的边缘,您可以减小像元大小或增加图像大小。
请注意,这只影响输出文件,而不影响您在 R 运行时看到的 R 绘图区域。
例子:

library(pheatmap)
set.seed(1)
data <- as.data.frame(matrix(rnorm(600), ncol=20))
rownames(data) <- paste(rownames(data), "looooong text")
然后...
# Doesn't fit on image
pheatmap(data, filename = "/tmp/example_1.png",
cellwidth = 20, cellheight = 20,
width = 7, height=9.1)
too large
# Change cell sizes, keep width/height fixed
pheatmap(data, filename = "/tmp/example_2.png",
cellwidth = 10, cellheight = 10, # <--- changed here
width = 7, height=9.1)
small cells
# Change width/height, keep cell sizes fixed
pheatmap(data, filename = "/tmp/example_3.png",
cellwidth = 20, cellheight = 20,
width = 9, height=10) # <--- changed here
big plotting area

关于r - 使用 pheatmap 时裁剪的列标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44701207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com