利用 ggplot2 绘制 Seurat 对象中的 tSNE 或 UMAP 图

Seurat 软件自带的绘图函数 DimPlot 虽然也提供了一些参数来供我们调整图形,但有时仍然有些你希望的功能不太容易实现,比如将细胞聚类分成三组,每一组是一种颜色,利用 DimPlot 就不容易实现(步骤比较繁琐:需要给细胞的 meta.data 增加额外的分组标识列,然后用 group.by 参数来为不同的分组上色)。一种更灵活的方法是把 tSNE 或者 UMAP 降维的信息从 seurat 对象中提取出来,并利用 ggplot 作图。具体代码如下:

## 假设我们有 Seurat 对象存储在 seuratObj 变量中
## 用 tSNE 算法进行降维操作
seuratObj  <- RunTSNE(seuratObj, dims = 1:20, check_duplicates = FALSE)

## 提取 tSNE 降维信息到 tsne 
library(tidyverse)
tsne = seuratObj@reductions$tsne@cell.embeddings %>%
      as.data.frame() %>% cbind(tx = seuratObj@meta.data$seurat_clusters)

## 用 ggplot 绘图(假设所有的细胞被分为 6 个 cluster)
jpeg(file = "tSNE.by_cluster.jpg", width = 7, height = 7, units = "in", res = 600)
ggplot(tsne, aes(x = tSNE_1, y = tSNE_2, color = tx)) + 
      geom_point(size = 0.2, alpha = 1) + 
      scale_color_manual(values=c("1" = "red", "2" = "blue", "3" = "yellow", "4" = "darkred", "5" = "darkblue", "6" = "darkorange"))
dev.off()

ggplot 颜色名称和对应的色彩可以参考 这里 或者 这里

参考文献

Seurat DimPlot - Highlight specific groups of cells in different colours, https://stackoverflow.com/questions/59101791/seurat-dimplot-highlight-specific-groups-of-cells-in-different-colours

  • 6
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值