# Figure 1d(Pie charts)
# 定义细胞的颜色
micro<-"#53AFE6"
pre_micro<-"#2DA7C8"
BAM<- "#0DD1AD"
UN<-"grey"
Mo<-"#FCE80C"
Mo_Mg<-"#FABF00"
Mg<-"#E98934"
NK<-"#8c42a3"
ncam<-"#C2B4FC"
NKT<-"#DFA5F2"
DC<-"#bf7a58"
Tcells<-"#94112f"
Bcells<-"#EC5CA5"
freq_list <- lapply(sex_condition_objects, function(x) {
freq <- data.frame(cell_type = x$cell_type)
freq <- freq %>%
group_by(cell_type) %>%
count() %>%
ungroup %>%
mutate(per = `n`/sum(`n`))%>%
mutate(text_y=1-{cumsum(per)-per/2})#####重点是这一句给ggrepel指定一个纵坐标
freq$cell_type <- factor(freq$cell_type, levels= c("micro", "pre-micro", "macro", "BAM", "NKT","NK", "B-cells", "T-cells","Ncam1+", "DC", "UN"))
freq$cell_type=fct_drop(freq$cell_type)#移除多余的factor
freq$label <- scales::percent(freq$per)
freq
})
library(ggrepel)
cf<-ggplot(freq,#freq_list$`GSM4039241-F-ctrl`,
aes(x="", y=per, fill=cell_type))+
geom_bar(stat="identity", width=1, color="white")+
coord_polar("y", start=0)+
scale_fill_manual(values=c(micro, pre_micro, BAM, UN))+
theme_void()+
geom_label_repel(aes(x="", y=text_y,label = label), size=3, show.legend = F, nudge_x = 1,hjust=0.5)
#####重点是y=text_y,
cf
可以回顾copper的突变瀑布图右下角的柱状图