######Video source: https://ke.biowolf.cn
######??????ѧ??: https://www.biowolf.cn/
######΢?Ź??ںţ?biowolf_cn
######???????䣺biowolf@foxmail.com
######????΢??: 18520221056

#install.packages("ggplot2")
#install.packages("ggalluvial")


#???ð?
library(ggalluvial)
library(ggplot2)
library(dplyr)

clusterFile="cluster.txt"         #???ͽ????ļ?
setwd("C:\\Users\\LZD\\Desktop\\THCA\\PANoptosis\\34.ggalluvial")     #???ù???Ŀ¼

#??ȡ?????ļ?
rt=read.table(clusterFile, header=T, sep="\t", check.names=F, row.names=1)

#׼??ɣ??ͼ?????ļ?
rt=rt[,c("risk", "Cluster")]
colnames(rt)=c("Risk", "Cluster")
corLodes=to_lodes_form(rt, axes = 1:ncol(rt), id = "Cohort")

#?õ??????ļ?
pdf(file="ggalluvial.pdf", width=7, height=5)
mycol=rep(c("#FF0000","#0000FF","#0066FF","#FF9900","#00DB00","#FF0000","#D8D155","#223D6C","#D20A13","#431A3D","#91612D","#FFD121","#088247","#11AA4D","#58CDD9","#7A142C","#5D90BA","#64495D","#7CC767"),15)
ggplot(corLodes, aes(x = x, stratum = stratum, alluvium = Cohort,fill = stratum, label = stratum)) +
  	 scale_x_discrete(expand = c(0, 0)) +  
  	 #??aes.flow??????????ɫ??forward˵??????????ɫ??ǰ??????״ͼһ?£?backward˵???ͺ???????״ͼһ?¡?
  	 geom_flow(width = 2/10,aes.flow = "backward") + 
	 geom_stratum(alpha = .9, width = 3/10) +
	 scale_fill_manual(values = mycol) +
	 #size=3??????????С
	 geom_text(stat = "stratum", size = 3,color="black") +
	 xlab("") + ylab("") + theme_bw() + 
	 theme(axis.line = element_blank(),axis.ticks = element_blank(),axis.text.x = element_blank()) + #ȥ????????
	 theme(panel.grid =element_blank()) + 
	 theme(panel.border = element_blank()) + 
	 coord_flip() + ggtitle("") + guides(fill = FALSE)                            
dev.off()


######Video source: https://ke.biowolf.cn
######??????ѧ??: https://www.biowolf.cn/
######΢?Ź??ںţ?biowolf_cn
######???????䣺biowolf@foxmail.com
######????΢??: 18520221056

