I'm trying to reproduce a mobility flow diagram and don't really know how to add additional colour transparency to the fill argument based on axis2 categories. Or whether that's even the way to go about solving this problem!
Any suggestions would be greatly appreciated, thanks!
What I'm trying to achieve: Mobility flow diagram
What I have: My mobility flow diagram example
Code for my mobility flow diagram example:
library(ggplot2)
library(ggalluvial)
oclass <- c("1st", "1st", "1st", "2nd", "2nd", "2nd", "3rd", "3rd", "3rd")
dclass <- c("1st", "2nd", "3rd", "1st", "2nd", "3rd", "1st", "2nd", "3rd")
Freq <- c(700, 200, 100, 200, 600, 200, 50, 250, 700)
odclass <- data.frame(oclass, dclass, Freq)
ggplot(odclass, aes(y = Freq, axis1 = oclass, axis2 = dclass)) +
geom_alluvium(aes(fill = oclass), width = 1/6, reverse = TRUE) +
geom_stratum(width = 1/6, alpha = 0, reverse = TRUE, color = "black") +
geom_text(aes(label = after_stat(stratum)), stat = "stratum", reverse = TRUE, size=5) +
scale_fill_manual(values = c("darkcyan", "darkgoldenrod2", "mediumorchid")) +
theme_minimal() +
theme(axis.title.y = element_blank(), axis.text.y= element_blank(), legend.position = "none",
plot.title = element_text(hjust=0.5, size=18), axis.text.x = element_blank())