日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

基于VlnPlot參數(shù)及ggplot2美化小提琴圖

 健明 2024-10-09 發(fā)布于廣東

前情提要

上期的推文VlnPlot結(jié)果及常用參數(shù)淺析整理介紹了一下小提琴圖可視化marker基因,在結(jié)尾簡(jiǎn)單介紹了一下可用于美化可視化結(jié)果的參數(shù)。

這期我們就一起來(lái)使用一下這些參數(shù),繪制更好看的小提琴圖叭!

分析數(shù)據(jù)簡(jiǎn)介

因?yàn)榉治鲋行枰玫椒纸M信息,而pbmc3k的數(shù)據(jù)集是單個(gè)樣品,沒(méi)有包含分組信息。所以這期的示例數(shù)據(jù)換為ifnb.SeuratData的數(shù)據(jù)集

ifnb.SeuratData數(shù)據(jù)降維聚類分群的內(nèi)容見(jiàn)推文——ifnb數(shù)據(jù)集分析及注釋對(duì)比

最后的手動(dòng)分群情況

獲取top3的Marker基因:

markers <- FindAllMarkers(sce.all.int, only.pos = TRUE, min.pct = 0.25,  logfc.threshold = 0.25, verbose = FALSE)

top3 = markers %>% group_by(cluster) %>% top_n(n = 3, wt = avg_log2FC)
g2 = unique(top3$gene)

基于VlnPlot參數(shù)美化小提琴圖

1. 直接可視化

VlnPlot(sce.all.int, features = g2[1:6])

如果直接使用VlnPlot可視化,不設(shè)置參數(shù),會(huì)得到每個(gè)基因單獨(dú)展示的結(jié)果,不太易讀

如果想將marker一起展示,就需要使用stack參數(shù)繪制堆疊小提琴圖

2. 堆疊小提琴圖

#使用paletteer包來(lái)調(diào)用awtools包中的調(diào)色板函數(shù)
library(paletteer)

color <- c(paletteer_d("awtools::bpalette"),
           paletteer_d("awtools::a_palette"),
           paletteer_d("awtools::mpalette"))

#stack=T繪制堆疊小提琴圖
p1 <- VlnPlot(sce.all.int,features=g2,
              group.by="celltype",
              stack=T,cols=color
)

#去掉標(biāo)簽注釋
p1+NoLegend()

可以使用flip參數(shù)進(jìn)行翻轉(zhuǎn),使得結(jié)果更加易讀

p1 <- VlnPlot(sce.all.int,features=g2,
              group.by="celltype",
              flip=T,stack=T,cols=color
)

p1+NoLegend()

3. 分組小提琴圖

分組小提琴圖是一種用于展示不同組別中數(shù)據(jù)分布情況的可視化圖表,當(dāng)有兩個(gè)組別時(shí)可以很好的展示基因在兩個(gè)組間的差異

使用split.by參數(shù)可選擇按照某一分組變量(這里是 'stim')來(lái)分割數(shù)據(jù)

p2 <- VlnPlot(sce.all.int, g2, stack = TRUE,
              split.by = 'stim',flip=T, add.noise = T,
              cols = c("#78C2C4","#C73E3A"),) ;p2

從圖中可以看到pDC相關(guān)基因主要在STIM組高表達(dá),有些基因僅在STIM或者只在CTRL組表達(dá)

4. 分組分半小提琴圖

也可以在同一個(gè)圖形中繪制多個(gè)分組的分布,可以直觀地比較不同組之間的數(shù)據(jù)分布情況,以便進(jìn)行統(tǒng)計(jì)分析和推斷。

使用split.plot = T生成每個(gè)分組的單獨(dú)小提琴圖

p<-VlnPlot(sce.all.int, features = g2,stack=T,
           pt.size=0,flip = T,add.noise = T,
           split.by = 'stim',
           group.by = "celltype",
           cols = c("#78C2C4","#C73E3A"),
           split.plot = T)

將分組以及分組且分半小提琴圖拼圖,可以更加直觀的看到兩個(gè)分組之間基因表達(dá)的差異

使用ggplot2進(jìn)行美化

因?yàn)?strong style="color: rgb(0, 0, 0);background-attachment: scroll;background-clip: border-box;background-image: none;background-origin: ;background-position: 0% 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;border-style: none;border-width: 3px;border-color: rgba(0, 0, 0, 0.4);border-radius: 0px;">VlnPlot是一個(gè)ggplot的對(duì)象,所以可以基于ggplot2進(jìn)行美化?;蛘?strong style="color: rgb(0, 0, 0);background-attachment: scroll;background-clip: border-box;background-image: none;background-origin: ;background-position: 0% 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;border-style: none;border-width: 3px;border-color: rgba(0, 0, 0, 0.4);border-radius: 0px;">提取需要的數(shù)據(jù),使用ggplot2直接繪制小提琴圖

1. 美化VlnPlot結(jié)果

可以基于ggplot2的theme函數(shù)去調(diào)整坐標(biāo)軸,設(shè)置文本顏色和大小、添加邊框、調(diào)整間距等

p1 + theme_bw()+
  theme(
    axis.text.x.bottom = element_text(angle = 45,hjust = 1,vjust = 1),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    legend.position = "none",
    axis.text.x = element_text(color = 'black',size = 11),
    axis.text.y = element_blank(),
    axis.title.x = element_text(color = 'black', size = 15),
    axis.ticks.x = element_line(color = 'black'),
    axis.ticks.y = element_blank(),
  )
  • 旋轉(zhuǎn)并對(duì)齊 x 軸標(biāo)簽,設(shè)置其樣式;
  • 取消 x 軸的次要網(wǎng)格線與 y 軸的刻度標(biāo)簽;
  • 隱藏圖例;
  • 設(shè)置 x 軸標(biāo)題和刻度線的顏色和大??;
  • 完全取消 y 軸的刻度和網(wǎng)格線,以簡(jiǎn)化圖形展示。
p1+theme_minimal()+
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        axis.text.y = element_blank(),
        axis.title = element_text(size = 12),
        legend.position = 'none')+
  scale_fill_manual(values = color)+
  labs(title = 'Top 3 markers for each cluster',
       x = 'Cluster',
       y = 'Expression')

通過(guò)theme_minimal()theme()函數(shù)對(duì)圖形的樣式進(jìn)行美化:

  • 將 x 軸標(biāo)簽旋轉(zhuǎn) 45 度并右對(duì)齊;
  • 隱藏 y 軸的刻度標(biāo)簽;
  • 設(shè)定軸標(biāo)題的字體大??;
  • 移除圖例;
  • 自定義填充顏色;
  • 添加標(biāo)題和軸標(biāo)簽。

2. 提取數(shù)據(jù)使用ggplot2進(jìn)行美化

小謝私認(rèn)為基于ggplot2的theme函數(shù)美化VlnPlot結(jié)果已經(jīng)比較好看了,但由于是VlnPlot結(jié)果的框架下,可能還是會(huì)有些限制

如果需要高度定制化小提琴的圖的結(jié)果,也可以提取需要的數(shù)據(jù),使用ggplot2從繪圖到美化。

之前的前輩們已經(jīng)整理好了提取數(shù)據(jù)進(jìn)行可視化的方法:

小結(jié)

這期使用VlnPlot函數(shù)的相關(guān)參數(shù),繪制堆疊小提琴圖,以及對(duì)小提琴圖進(jìn)行了分組分半的展示

基于ggplot2在VlnPlot結(jié)果的基礎(chǔ)上進(jìn)行調(diào)整,如果想提取需要的數(shù)據(jù),使用ggplot2從繪圖到美化,可以參考前輩們整理的推文!

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

    0條評(píng)論

    發(fā)表

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

    類似文章 更多