I tried to use R's ggplot2 and ggalluvial to draw sankey, at first my code is
ggplot(as.data.frame(mydata_alluvia),aes(y=FDI.changes,axis1=Primary.sender,axis2=Target.state))+
geom_alluvium(aes(fill=Episodes),width=0)+
geom_stratum(width=1/8,fill="white",color="grey")+
geom_text(stat="stratum",label.strata=TRUE,size=1.5,check_overlap = TRUE)+
scale_x_discrete(limits=c("Primary sender","Target state"),expand=c(.05,.05))+
scale_fill_brewer(type = "qual",palette="Set1")+
ggtitle("Sanctions during 1970-2017")
the gragh came out, but the countries are too many to see it clearly, so then I want to color the countries by their regions, to make the cylindrical colorful rather than white, the code is:
ggplot(as.data.frame(mydata_alluvia),aes(y=FDI.changes,axis1=Primary.sender,axis2=Target.state))+
geom_alluvium(aes(fill=Episodes),width=0)+
geom_stratum(width=1/8,fill=factor(mydata$Target.region),color="grey")+
geom_text(stat="stratum",label.strata=TRUE,size=1.5,check_overlap = TRUE)+
scale_x_discrete(limits=c("Primary sender","Target state"),expand=c(.05,.05))+
scale_fill_brewer(type = "qual",palette="Set1")+
ggtitle("Sanctions during 1970-2017")
the error cooured:
Error: Aesthetics must be either length 1 or the same as the data (122): fill
I think I wrote the wrong code of the geom_stratum(fill=) , but how to write the right one?
could you pls help me? thanks