本系列推送旨在带领生信零基础的科研人一起入门单细胞(核)转录组数据分析。 在单细胞RNA测序(scRNA-seq)研究中,Dotplot图是一种重要的可视化工具,用于展示基因表达模式和细胞群之间的差异。Dotplot图可以快速而直观地比较单个基因在不同细胞亚群中的表达水平,并发现可能存在的生物学趋势或群体特征。 Introduction 本期内容中,我们将使用几种方法来绘制Dotplot图,以展示单细胞数据的丰富内容,并学会如何利用Dotplot图揭示细胞之间的差异和特征。让我们一起来学习吧,探索单细胞世界中隐藏的宝藏!加载需要的包和数据:
library(Seurat) library(clustree) library(cowplot) library(tidyverse) library(dplyr) library(patchwork) library(ggplot2)
上期 (单细胞组学 | 第20期. 美无极限——卷起来的UMAP图美化方案),我们完成了细胞注释,学习了各种美化UMAP图的配色方法,接下来根据注释的细胞类型绘制dotplot图。 准备关注的差异基因
Dotplot图在单细胞RNA测序研究中具有多种作用,如展示基因表达模式,发现细胞群差异,生物学趋势分析,辅助生物学解释,数据探索和验证等。根据不同的作图需要,我们需要得到不同细胞类群的差异基因或者我们关注的一些基因集,在这里我们用细胞类群的主要marker基因来展示不同细胞亚群的差异。 Hu_AO_db_QC2 <- FindClusters(Hu_AO_db_QC2,resolution = 0.2) all_markers = FindAllMarkers(Hu_AO_db_QC2, only.pos = T, #只会去找某一群特定上调的基因 logfc.threshold=0.5,#倍数的对数的阈值,默认是0.25 min.pct = 0.5)
top3_markers <- as.data.frame(all_markers %>% group_by(cluster) %>% top_n(n = 3, wt = avg_log2FC)) top3_markers
画图 (1)最简单的版本 colors2 <- c("#96C3D8", "#F5B375", "#C0937E", "#67A59B", "#A5D38F", "#8D75AF", "#F19294", "#E45D61", "#BDA7CB") p1<-DotPlot(Hu_AO_db_QC2,features = top3_markers$gene,group.by ='Major_celltype',cols = colors2)+RotatedAxis() p1
p2<-DotPlot(Hu_AO_db_QC2, features = split(top3_markers$gene, top3_markers$cluster),group.by ='Major_celltype', cols =c ("#67A59B", "#A5D38F"))+RotatedAxis() p2
p <- DotPlot(Hu_AO_db_QC2, features = unique(top3_markers$gene) , assay='RNA',group.by ='Major_celltype' ) + coord_flip() + #翻转 theme(panel.grid = element_blank(), axis.text.x=element_text(angle = 45, hjust = 0.5,vjust=0.5))+ #轴标签 labs(x=NULL,y=NULL) + guides(size = guide_legend("Percent Expression") )+ #legend scale_color_gradientn(colours = c('#330066','#336699','#66CC66')) #颜色 p
p <- DotPlot(Hu_AO_db_QC2, features = top3_markers$gene,group.by ='Major_celltype') exp <- p$data library(ggplot2) p1 <- ggplot(exp,aes(x=features.plot,y=id))+ geom_point(aes(size=`pct.exp`, color=`avg.exp.scaled`))+ theme_bw()+coord_flip()+ theme(panel.grid = element_blank(), axis.text.x=element_text(hjust = 1,vjust=0.5))+ scale_color_gradient(low="lightgrey",high="blue")+ labs(x=NULL,y=NULL)+guides(size=guide_legend(order=3)) p1 #基因聚类 library(ggtree) df1<-reshape2::dcast(exp,id~features.plot,value.var = "avg.exp.scaled") rownames(df1)<-df1[,1] df1 <- df1[,-1] df1 <- t(df1) head(df1) p4<-ggtree(hclust(dist(df1))) #分组聚类 p3 <- ggtree(hclust(dist(t(df1))))+layout_dendrogram() p3 #合并图形 library(aplot) p1%>%insert_left(p4) p1%>%insert_top(p3,height = 0.15)%>%insert_left(p4,width = 0.3) library(patchwork)
(5)另一种画法的整合修饰使用了aplot包,也在这里分享一下p <- DotPlot(Hu_AO_db_QC2, features = top3_markers$gene, cols = my36colors, group.by = 'Major_celltype')+coord_flip() exp <- p$data library(forcats) exp$features.plot <- as.factor(exp$features.plot) exp$features.plot <- fct_inorder(exp$features.plot)
p2 <- ggplot(exp,aes(x=id,y= features.plot))+ geom_point(aes(size=`pct.exp`, color=`avg.exp.scaled`))+theme_bw()+ theme(panel.grid = element_blank(), axis.text.x=element_text(angle=90,hjust = 1,vjust=0.5))+ scale_color_gradientn(values = seq(0,1,0.2),colours = c('#6699CC','#FFFF99','#CC3333'))+ labs(x=NULL,y=NULL)+guides(size=guide_legend(order=3))+ theme(legend.direction = "horizontal", legend.position = "bottom")
library(aplot) p2%>% insert_left(p4,width = 0.3)%>%insert_top(p3,height = 0.3)
|