如何调整R中DoHeatmap图中的簇大小(列)?

问题描述 投票:0回答:3

我想从 Seurat 对象data获取热图。为了读取数据,我尝试了这段代码

visium_x22117 = Load10X_Spatial(data.dir = "~/PhD_Project_Moh_Huda/Dataset_files/X22117_Visium_scRNA/", filename = "X22117_filtered_feature_bc_matrix.h5")
suppressWarnings({visium_x22117 = SCTransform(visium_x22117, assay = "Spatial", verbose = FALSE)

visium_x22117})

为了得到下面的情节我已经尝试过

visium_x22117.markers %>%
group_by(cluster) %>%
top_n(n = 10, wt = avg_log2FC) -> top10
heatmap = DoHeatmap(visium_x22117, features = top10$gene)
heatmap

然而,该图看起来非常拥挤,并且簇 0 的列大小比其他簇大得多。我已经使用 ?DoHeatmap 检查了 DoHeatmap 的文档,但找不到调整大小以使绘图看起来更好的方法。我怎样才能让它变得更好?

r plot heatmap
3个回答
1
投票

您可以将

theme
axis.text
中的
ggplot2
一起使用,因为
DoHeatmap
返回一个 ggplot 对象。这是一个更改轴标签大小的可重现示例(您可以调整大小):

library(Seurat)
#> Attaching SeuratObject
library(ggplot2)
data("pbmc_small")
p <- DoHeatmap(object = pbmc_small)
p

p + theme(axis.text=element_text(size=2))

创建于 2023-01-04,使用 reprex v2.0.2


0
投票

每个簇都由引用单个细胞的微小列组成,并且由于每个簇内的细胞数量不同,因此您无法在 Seurat 中更改它。但您可以修改它,因为热图是一个 ggplot 对象。

要以@Quinten 的答案为基础,请尝试,

p + theme(panel.spacing.x = unit(0.5, "cm")) 

或者任何你想要的间距


0
投票

您好,您可以尝试像这样对数据进行下采样:

top_tc_markers = markers_tc %>%
     group_by(cluster) %>%
     dplyr::filter(avg_log2FC > 1) %>%
     slice_head(n = 10) %>%
     ungroup() -> top10 options(repr.plot.width=25, repr.plot.height=25) DoHeatmap(subset(tcell_data, downsample = 100),
 features = top10$gene) + NoLegend() + 
     theme(text = element_text(size = 20))
© www.soinside.com 2019 - 2024. All rights reserved.