细胞数据统计

>计算cluster细胞数目
library(ggsci)
cell_stat_df <- table(sce_all.intergrated@meta.data$celltype, sce_all.intergrated@meta.data$orig.ident) %>% 
  reshape2::melt()
colnames(cell_stat_df) <- c("ClusterName","Sample","Count")
cell_stat_df$ClusterName <- factor(cell_stat_df$ClusterName)
Colors = pal_igv("default")(51)

ggplot(data = cell_stat_df, aes(x = Count, y = Sample, fill =  ClusterName)) +
  geom_bar(stat = "identity", width=0.8, position="fill")+
  scale_fill_manual(values = Colors_vector[1:15]) +
  theme_bw()+
  theme(panel.grid =element_blank()) +
  labs(x="Ratio",y="")+
  theme(axis.text.y = element_text(size=12, colour = "black"))+
  theme(axis.text.x = element_text(size=12, colour = "black"))+
  theme(axis.text.x.bottom = element_text(hjust = 1, vjust = 1, angle = 45))

>计算cluster细胞比率
cell_ratio_df  <- prop.table(table(Idents(sce_all.intergrated), sce_all.intergrated$orig.ident), margin = 2)
cell_ratio_df  <- cell_ratio_df %>% as.data.frame()
cell_ratio_df $Var1 <- as.integer(cell_ratio_df $Var1)
cell_ratio_df <- cell_ratio_df %>% left_join(celltype, by = c("Var1"="ClusterID"))
Colors = pal_igv("default")(51)

ggplot(data = cell_ratio_df , aes(x =Var2, y = Freq, fill =  celltype)) +
  geom_bar(stat = "identity", width=0.8, position="fill")+
  scale_fill_manual(values = Colors[1:15]) +
  theme_bw()+
  theme(panel.grid =element_blank()) +
  labs(x="",y="Ratio")+
  theme(axis.text.y = element_text(size=12, colour = "black"))+
  theme(axis.text.x = element_text(size=12, colour = "black"))+
  theme(axis.text.x.bottom = element_text(hjust = 1, vjust = 1, angle = 45)) 


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容