最近在复现Cellular heterogeneity during mouse pancreatic ductal adenocarcinoma progression at single-cell resolution 这篇文章的聚类分群时注意到论文图中把细胞亚群的比例也显示在图中,如图
发现自己还没有绘制过类似的比例图,遂查询了资料,发现了生信技能树在前几天刚好有一篇帖子做了这方面的介绍,所以直接拿来用了,这里坐下简单的记录。原贴链接:https://mp.weixin.qq.com/s/OflFEujZ8x_qVKAoW3xVsQ。
首先基于常规的单细胞测序流程得到的late KIC的seurat对象(手动注释错了应该,与文章结果相差太大,不影响演示计算亚群比例)。
DimPlot(sce.all.int, reduction = "tsne",raster = F,group.by = 'RNA_snn_res.0.6',
label = T,repel = T) +
DimPlot(sce.all.int, reduction = "tsne",raster = F,group.by = 'celltype',
label = T,repel = T)
ggsave(paste('paper_anno_and_tsne.pdf'),width = 12,height = 10)
df=data.frame(clu=names(table(sce.all.int$seurat_clusters)),
per=sprintf("%1.2f%%",100*table(sce.all.int$seurat_clusters)/length(sce.all.int$seurat_clusters)))
sce.all.int$per=df[match(sce.all.int$seurat_clusters,df$clu),2]
sce.all.int$new=paste0(sce.all.int$seurat_clusters,":",sce.all.int$celltype,"(",sce.all.int$per,")")
table(sce.all.int$new)
DimPlot(sce.all.int,reduction='tsne',
group.by='new',
label.box=T,label=T,repel=T)
ggsave(paste('paper_anno_percentage.pdf'),width = 12,height = 10)
或者label=T设置为F,则只在图例上显示比例,不在具体的分群中显示比例。
比基础函数还是好看很多的。
PropPlot <- function(object, groupBy){
# (1)获取绘图数据
plot_data = object@meta.data %>%
dplyr::select(orig.ident, {{groupBy}}) %>%
dplyr::rename(group = as.name(groupBy))
# (2)绘图
figure = ggbarstats(data = plot_data,
x = group, y = orig.ident,
package = 'ggsci',
palette = 'category20c_d3',
results.subtitle = FALSE,
bf.message = FALSE,
proportion.test = FALSE,
label.args = list(size = 2,
fill = 'white',
alpha = 0.85,
family = 'Arial',
fontface = 'bold'),
perc.k = 2,
title = '',
xlab = '',
legend.title = 'Seurat Cluster',
ggtheme = ggpubr::theme_pubclean()) +
theme(axis.ticks.x = element_blank(),
axis.ticks.y = element_line(color = 'black', lineend = 'round'),
legend.position = 'right',
axis.text.x = element_text(size = 15, color = 'black', family = 'Arial'),
axis.text.y = element_text(size = 15, color = 'black', family = 'Arial'),
legend.text = element_text(family = 'Arial', size = 10, color = 'black'),
legend.title = element_text(family = 'Arial', size = 13, color = 'black'))
# (3)去除柱子下面的样本量标识:
gginnards::delete_layers(x = figure, match_type = 'GeomText')
}
#调用函数
library(gginnards)
PropPlot(object = sce.all.int, groupBy = 'celltype')
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。