2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

5種方式美化你的單細(xì)胞umap散點(diǎn)圖

 健明 2025-01-11 發(fā)布于廣東

我們生信技能樹(shù)的單細(xì)胞月更群里面經(jīng)常看到小伙伴提出的圖片美化需求,這就來(lái)看看單細(xì)胞umap美化工具吧!

第一種:SCP 包(這個(gè)包非常的出色)

關(guān)于SCP,我們前面也有一個(gè)專(zhuān)門(mén)的專(zhuān)輯對(duì)其進(jìn)行了大篇幅的介紹,不知道大家用起來(lái)了沒(méi)呢?

其學(xué)習(xí)的官網(wǎng)地址為:https://zhanghao-njmu./SCP/index.html

沒(méi)有安裝的,這次就不要再錯(cuò)過(guò)啦:

# 安裝
devtools::install_github("zhanghao-njmu/SCP")

本次,我們使用的數(shù)據(jù)為來(lái)自 GSE128531 數(shù)據(jù)注釋后的seurat對(duì)象,你自己用的時(shí)候可以使用任何一個(gè)經(jīng)過(guò)了注釋后的seurat對(duì)象。

rm(list=ls())
library(COSG)
library(harmony)
library(ggsci)
library(dplyr) 
library(future)
library(Seurat)
library(clustree)
library(cowplot)
library(data.table)
library(dplyr)
library(ggplot2)
library(patchwork)
library(stringr)
library(qs)

# 導(dǎo)入數(shù)據(jù)
sce.all.int <- readRDS('2-harmony/sce.all_int.rds')
sp <- 'human'
head(sce.all.int@meta.data)
load("phe.Rdata")
head(phe)
sce.all.int <- AddMetaData(sce.all.int, metadata = phe)

Idents(sce.all.int) <- "celltype"
table(Idents(sce.all.int))

看一下它對(duì)UMAP可視化的厲害之處!

1、先看默認(rèn)主題一鍵出圖:

################## umap1
library(SCP)
head(sce.all.int@meta.data)
CellDimPlot(sce.all.int, group.by = "celltype", reduction = "UMAP")

這個(gè)配色非常CNS,且圖中展示了總細(xì)胞數(shù),每個(gè)亞群的細(xì)胞數(shù)這些信息:

2、坐標(biāo)改成 左下小箭頭,也是大家非常常見(jiàn)的需求!

# 左下小箭頭
CellDimPlot(sce.all.int, group.by = "celltype", reduction = "UMAP", theme_use = "theme_blank")

3、只顯示X、Y軸

還可以一鍵調(diào)整整體字體大小

CellDimPlot(sce.all.int, group.by = "celltype", reduction = "UMAP"
            theme_use = ggplot2::theme_classic, theme_args = list(base_size = 16))

上面三個(gè)是我最喜歡的ump風(fēng)格,還有很多其他,總有你的一款:

第二種:Nebulosa(r包)

Nebulosa 是一個(gè)基于核密度估計(jì)可視化單細(xì)胞數(shù)據(jù)的 R 包,主要通過(guò)結(jié)合細(xì)胞之間的相似性來(lái)恢復(fù)丟失特征中的信號(hào),從而實(shí)現(xiàn)細(xì)胞特征的“卷積”。

學(xué)習(xí)官網(wǎng):https:///packages/devel/bioc/vignettes/Nebulosa/inst/doc/nebulosa_seurat.html

Nebulosa 的主要功能是 plot_density,讓我們按照以下方式繪制 一些marker基因 的核密度估計(jì)圖,展示的marker基因表達(dá)水平高低

# 安裝一下
options(BioC_mirror="https://mirrors./bioconductor")
options("repos"=c(CRAN="https://mirrors./CRAN/"))
BiocManager::install("Nebulosa")
library(Nebulosa)

1、 繪制一個(gè)基因PTPRC

這種圖也是在很多CNS級(jí)別的文章中出現(xiàn)的:

# 繪制一個(gè)基因PTPRC
p1 <- plot_density(sce.all.int, c("PTPRC"),size = 0.3)
p1

2、繪制多個(gè)基因

# 同時(shí)繪制多個(gè)基因
p3 <- plot_density(sce.all.int, c("CD3D","CD4","CD8A","CD68"),size = 0.3)
p3

結(jié)果如下:

3、繪制基因共表達(dá)

這里可以同時(shí)展示兩個(gè)基因都表達(dá)的地方:

# combine = FALSE 只保留兩個(gè)基因都表達(dá)的區(qū)域
p4 <- plot_density(sce.all.int, c("CD8A""CCR7"), joint = TRUE,combine = FALSE) 
p4

第三種:scCustomize(r包)

學(xué)習(xí)官網(wǎng):https://samuel-marsh./scCustomize/index.html

# 安裝
# Base R
install.packages("scCustomize")

繪圖:可以繪制一個(gè)marker,也可以展示多個(gè)marker

################## umap4:scCustomize
library(viridis)
library(Seurat)
library(scCustomize)

FeaturePlot_scCustom(seurat_object = sce.all.int, features = c("VWF","CD3E"), order = F)

這種風(fēng)格很像早期的椒鹽繪圖風(fēng)格:你看這個(gè)著色點(diǎn)是不是很像灑在雞腿上面的椒鹽!(椒鹽風(fēng)格這個(gè)詞我在一篇單細(xì)胞文獻(xiàn)中遇到過(guò),現(xiàn)在找不見(jiàn)了,當(dāng)時(shí)還專(zhuān)門(mén)在群里問(wèn)了來(lái)著哈哈哈哈)

還可以輕松地修改配色:

# 修改顏色
# Set color palette
pal <- viridis(n = 10, option = "D")
FeaturePlot_scCustom(seurat_object = sce.all.int, features = c("VWF","CD3E"), 
                     colors_use = pal, order = T,pt.size = 0.3)

第四種:ggplot2繪制細(xì)胞密度umap圖

在seurat包中有人提出一個(gè)繪圖需求:https://github.com/satijalab/seurat/issues/6962

這種圖主要用來(lái)處理數(shù)據(jù)點(diǎn)重疊問(wèn)題時(shí)非常有用,使用 MASS::kde2d() 進(jìn)行二維核密度估計(jì),并通過(guò)等高線顯示結(jié)果,geom_density_2d() 繪制等高線,而 geom_density_2d_filled() 繪制填充的等高線帶。

鏈接:https://ggplot2./reference/geom_density_2d.html

library(cetcolor)
library(Seurat)
library(ggplot2)

# 設(shè)置顏色
scale.col <- cet_pal(16, name = "fire")

# generate UMAP plot
pl1 <- UMAPPlot(sce.all.int, combine = FALSE) # returns full ggplot object
pl1

# make plot
pl1[[1]] & 
  stat_density_2d(aes_string(x = "umap_1", y = "umap_2", fill = "after_stat(level)"), 
                  linewidth = 0.2, geom = "density_2d_filled"
                  colour = "ivory", alpha = 0.4, n = 150, h = c(1.2, 1.2)) & 
  scale_fill_gradientn(colours = scale.col) & 
  DarkTheme()

這種風(fēng)格很獨(dú)特:

第五種:ggpointdensity(r包)

在二維坐標(biāo)系中可視化數(shù)據(jù)點(diǎn)有幾種方法:如果你有大量的數(shù)據(jù)點(diǎn)重疊在一起,geom_point() 無(wú)法為你提供重疊點(diǎn)的數(shù)量估計(jì)。

剛剛上面介紹的geom_density2d()geom_bin2d() 可以解決這個(gè)問(wèn)題,但它們使得無(wú)法調(diào)查個(gè)別異常點(diǎn),而這些異常點(diǎn)可能具有研究?jī)r(jià)值。

geom_pointdensity() 旨在通過(guò)結(jié)合兩者的優(yōu)點(diǎn)來(lái)解決這個(gè)問(wèn)題:各個(gè)點(diǎn)根據(jù)鄰近點(diǎn)的數(shù)量進(jìn)行著色。這使得你既能看到整體分布,也能看到個(gè)別點(diǎn)。

學(xué)習(xí)官網(wǎng):https://github.com/LKremer/ggpointdensity

細(xì)胞密度圖:

# 安裝
install.packages("ggpointdensity")
library(ggpointdensity)

# 提取umap坐標(biāo)數(shù)據(jù)
dat <- Embeddings(sce.all.int, reduction = "umap")
head(dat)
# umap_1    umap_2
# SC67mf2_AAACCTGAGAGTAATC -3.541568  5.127461
# SC67mf2_AAACCTGAGCGCTTAT -6.623588 -3.025122
# SC67mf2_AAACCTGAGGACACCA -4.586405  1.513219

ggplot(data = dat, mapping = aes(x = umap_1, y = umap_2)) +
  geom_pointdensity() +
  scale_color_viridis()

當(dāng)然,它還可以展示marker特征基因表達(dá):

# 提取umap坐標(biāo)以及特征基因表達(dá)
df <- FetchData(object =sce.all.int, vars = c("umap_1""umap_2""CD3D"), layer = "data")
head(df)

# umap_1    umap_2     CD3D
# SC67mf2_AAACCTGAGAGTAATC -3.541568  5.127461 0.000000
# SC67mf2_AAACCTGAGCGCTTAT -6.623588 -3.025122 1.430228
# SC67mf2_AAACCTGAGGACACCA -4.586405  1.513219 0.000000

p <- ggplot(df, aes(x= umap_1, y= umap_2 )) +
  geom_point(data = df %>% filter(CD3D == 0), color = "#440154FF", size = 0.6) +
  ggpointdensity::geom_pointdensity(data = df %>% filter(CD3D > 0), size = 0.6) +
  viridis::scale_color_viridis() +
  theme_classic(base_size = 14) +
  labs(color= "CD3D")
p

結(jié)果如下:

上面哪一款是你的菜?可以在評(píng)論區(qū)大聲說(shuō)出來(lái)(愛(ài)就要勇敢說(shuō)出來(lái)?。?/strong>

友情宣傳:

生信入門(mén)&數(shù)據(jù)挖掘線上直播課2025年1月班

時(shí)隔5年,我們的生信技能樹(shù)VIP學(xué)徒繼續(xù)招生啦

滿足你生信分析計(jì)算需求的低價(jià)解決方案

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章