我有一个热图,其中y轴的文本不断被切断。无论我尝试在RStudio导出中手动保存图像还是使用以下命令保存图像,文本都会被截断:
png(filename)
Heatmap(pathways, name = "log p-value", column_title = "Genesets",
cluster_rows = FALSE, row_names_side = "left", col = col_fun)
dev.off()我如何更改图形的宽度和高度也无关紧要-更改这些参数会改变热图正方形的大小,但截断的文本总是相同的量。
示例图像:

我已经剪掉了X轴,因为我不能分享它,它只有Y轴有问题,如图所示。另外,为了参考,我使用complexheatmap包制作了热图。
编辑:尝试这样做似乎也不会有任何效果:
par(mar=c(100,100,100,100)+10)
png(filename='test.png', width=700, height=700)
Heatmap(df_pathways, name = "log p-value", column_title = "Genesets",
cluster_rows = FALSE, cluster_columns = FALSE, row_names_side = "left", col = col_fun)
graphics.off()输入数据示例:
pathways <-
structure(list(Group1 = c(9.420318259, 4.836092781, 5.561049165,
8.190548144, 6.71227316, 4.095942487, 4.992794151, 5.552164863,
4.34153332, 5.895592291, 7.553546365, 4.992782053, 6.053009309,
6.860701322, 5.801092847, 5.148352899, 4.890727291, 4.228175167,
5.804415571, 4.589825753), Group2 = c(14.57805564, 10.81418654,
11.09736375, 10.32521712, 12.0145571, 10.07735354, 10.02001419,
9.218294382, 10.09808164, 8.177240205, 8.657878442, 9.835699421,
8.687931231, 8.31684452, 8.798453748, 7.760651767, 7.982599836,
8.300396581, 8.249833908, 7.951599435), Group3 = c(14.49131554,
13.3205827, 12.12174012, 10.44766272, 11.01869555, 11.09934699,
11.24184793, 10.09879495, 9.876597118, 9.654484641, 10.91601179,
9.873567424, 8.476802302, 8.318460384, 7.975284646, 7.409538041,
8.258878348, 6.821340952, 7.075861702, 7.922657108), Group4 = c(11.44447147,
10.69676399, 9.595976655, 8.394853352, 8.82546953, 7.762112046,
7.146613208, 7.773426526, 7.445916643, 6.928897709, 6.969416034,
7.90504739, 5.971561206, 6.126050462, 6.208332721, 6.93495916,
6.529806574, 5.727539932, 7.097356964, 4.882623805), Group5 = c(22.86835197,
12.70083108, 10.05632122, 8.487520597, 4.207896212, 10.08721586,
9.726807084, 9.539543451, 12.26094928, 12.23048716, 7.885614665,
6.993219914, 11.35470645, 11.22311857, 10.94297858, 9.214002287,
7.197041788, 10.59080554, 5.08232173, 9.237584441), Group6 = c(10.62687539,
12.39464562, 8.714396722, 7.436886904, 9.303280092, 8.266037496,
8.650863908, 7.753285867, 6.151852334, 7.227066955, 5.589700078,
7.271066145, 7.172215654, 6.000920914, 6.458410247, 5.790443124,
7.461916094, 7.272885252, 5.318945244, 6.308454021), Group7 = c(11.09404106,
11.13903127, 9.363613884, 8.811864251, 9.255305005, 8.082707248,
7.101057322, 8.064874227, 7.29823506, 7.154725479, 7.256169907,
7.56145848, 6.155332798, 6.349384361, 6.420303272, 7.232379137,
6.821000583, 5.934088344, 7.368454621, 5.0727153)), row.names = c("Cardiac Hypertrophy Signaling (Enhanced)",
"Estrogen Receptor Signaling", "Role of NFAT in Cardiac Hypertrophy",
"Protein Kinase A Signaling", "Molecular Mechanisms of Cancer",
"Opioid Signaling Pathway", "Hepatic Fibrosis Signaling Pathway",
"Gap Junction Signaling", "G-Protein Coupled Receptor Signaling",
"White Adipose Tissue Browning Pathway", "Sperm Motility", "Factors Promoting Cardiogenesis in Vertebrates",
"Nitric Oxide Signaling in the Cardiovascular System", "Relaxin Signaling",
"Cellular Effects of Sildenafil (Viagra)", "Insulin Secretion Signaling Pathway",
"Colorectal Cancer Metastasis Signaling", "Ovarian Cancer Signaling",
"PPARα/RXRα Activation", "Corticotropin Releasing Hormone Signaling"
), class = "data.frame")发布于 2021-03-27 02:20:01
请看我上面的评论:当你说“y轴的文本”时,我认为你在谈论截断的行标签。如果这确实是您正在努力解决的问题,那么将Heatmap参数row_names_max_width从默认的unit(6, "cm")增加到像row_names_max_width = unit(12, "cm")这样的值应该可以让您容纳更长的行标签。
library(ComplexHeatmap)
## using your provided data as df_pathways
Heatmap(df_pathways, name = "log p-value", column_title = "Genesets",
row_names_max_width = unit(12, "cm"),
cluster_rows = FALSE, cluster_columns = FALSE, row_names_side = "left")
#> Warning: The input is a data frame, convert it to the matrix.

https://stackoverflow.com/questions/66763776
复制相似问题