首页 > 解决方案 > 如何在 Seurat 的 DoHeatmap 图中重新排序单元格(ggplot2)

问题描述

我正在用 R 中的 Seurat 绘制热图

require(Seurat)
data <- data.frame(cell1=c(-0.5, 0.5), cell2=c(-0.8, 0.3), cell3=c(2.0, 0.1), cell4=c(1.0, 1.0))
rownames(data) <- c("gene1", "gene2")
test <- CreateSeuratObject(data)
test@scale.data <- data
DoHeatmap(test)

这就是我得到的

热图结果

我想在这里用自定义顺序重新排序单元格。我试过DoHeatmap(test, data.use=<reordered data>)然后p <- DoHeatmap(…, plot=FALSE)重新排序p$data,但无济于事

标签: rggplot2seurat

解决方案


我们可以强制p$data$cell一个因素并根据我们的需要指定级别。

set.seed(1)
(custom_order <- paste0("cell", sample(4)))
#[1] "cell2" "cell4" "cell3" "cell1"

创建绘图并重新排序

p <- DoHeatmap(test)
p$data$cell <- factor(p$data$cell, levels = custom_order)
p

在此处输入图像描述


推荐阅读