################################# 单细胞不同分组细胞比例的展示 #################################
library(Seurat)
library(ggplot2)
library(dplyr)
library(Seurat)
library(dplyr)
library(reshape2)
library(plyr)
library(ggplot2)
library(plotrix)
library(dplyr)
library(ggsci)
integrated@meta.data
cols=c("#20B2AA","#FFA500","#9370DB","#98FB98","#F08080","#1E90FF","#7CFC00",
"#808000","#FA8072","#7B68EE","#9400D3","#800080","#A0522D","#D2B48C","#D2691E","#87CEEB","#40E0D0","#5F9EA0",
"#FF1493","#0000CD","#008B8B","#FFE4B5","#8A2BE2","#228B22","#E9967A","#4682B4","#32CD32","#F0E68C","#FFFFE0","#EE82EE",
"#FF6347","#6A5ACD","#9932CC","#8B008B","#8B4513","#DEB887")
table(integrated$orig.ident)#查看各组细胞数
prop.table(table(Idents(integrated)))
table(Idents(integrated), integrated$orig.ident)#各组不同细胞群细胞数
Cellratio <- prop.table(table(Idents(integrated), integrated$orig.ident), margin = 2)#计算各组样本不同细胞群比例
Cellratio <- as.data.frame(Cellratio)
# 假设数据框为 df,第三列名为 column3
Cellratio$Freq <- c(48.12560857, 33.5310219, 55.46218487, 37.51465416, 54.99316005, 47.25274725,
34.32494279, 45.01891551, 55.19125683, 37.09150327, 47.61029412, 61.83574879,
56.38297872, 52.31213873, 38.996139, 47.41035857, 77.97356828, 16.75126904,
60.10928962, 17.64705882, 38.23529412, 51.87439143, 66.4689781, 44.53781513,
62.48534584, 45.00683995, 52.74725275, 65.67505721, 54.98108449, 44.80874317,
62.90849673, 52.38970588, 38.16425121, 43.61702128, 47.68786127, 61.003861,
52.58964143, 22.02643172, 83.24873096, 39.89071038, 82.35294118,61.76470588)
ggplot(Cellratio, aes(x = Var1, y = Freq, fill = Var2))+
geom_col()+
geom_text(aes(label = paste(round(Freq, 1),"%")),
position = position_stack(vjust = 0.5))+
theme_classic()+
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
scale_fill_manual(values = c("#FB8072", "#7BAFDE","#87CEEB", "#882E72","#B17BA6",
"#FF7F00", "#FDB462", "#E7298A", "#E78AC3","#33A02C",
"#B2DF8A", "#55A1B1", "#8DD3C7", "#A6761D","#E6AB02"))
image.png
参考:
https://www.jianshu.com/p/281a1f3af039
https://www.jianshu.com/p/920c431ace79
网友评论