Using the dev version of the ggforce package, I can create a Sankey diagram as follows (from the documentation)
data <- reshape2::melt(Titanic)
data <- gather_set_data(data, 1:4)
ggplot(data, aes(x, id = id, split = y, value = value)) +
geom_parallel_sets(aes(fill = Sex), alpha = 0.3, axis.width = 0.1) +
geom_parallel_sets_axes(axis.width = 0.1) +
geom_parallel_sets_labels(colour = 'white')
What I'm struggling with, is getting the y-axis variables ordered in any way other than the default, which appears to be reverse alphabetical. For example, changing the plot so Adult
appeared near the top of the plot, with Child
below.
I've tried re-leveling the factors before applying gather_set_data
, as well as re-leveling the y
variable after applying gather_set_data
, and neither appear to work. I've also tried defining them as characters and sorting in different orders but that also doesn't seem to work.
Any help would be appreciated.