I'm creating Sankey plots with 4 years observations, each year I have the same variables (nodes with the same label as the year before9. I would like to have the same colour for each node with the same label. Is this possible?
I tried with some option but I did not find a solution.
options = list(sankey="{
link: { colorMode: 'source'},
node: {colorMode:'string', colors: ['#1f78b4','#a6cee3', ]}}"), )
R code:
Sankey <- gvisSankey(SHIVALVCI_widefile_1016_sankey, from="Var1", to="Var2", weight="Freq",
options = list(sankey="{
link: { colorMode: 'source'},
node: {colorMode:'string', colors: ['#1f78b4','#a6cee3', ]}}"), )
and the label's name:
"IK","No prest"))
SHIVALVCI_widefile_1016$M48 <- factor(SHIVALVCI_widefile_1016$M48,
levels = c(1111,1112,1121,1122,1211,1212,1221,1222,2111,2112,2121,2122,2211,2212,2221,2222),
labels = c("All prest","IV ALV SH","IV ALV IK","IV ALV","IV SH IK","IV SH",
"IV IK","IV","ALV SH IK","ALV SH","ALV IK","ALV","SH IK","SH",
"IK","No prest"))
You should be able to do something like this relatively easily with
ggforce. The following seems to do the trick with Titanic data. I modified the code slightly from the example in?geom_parallel_setsto add afillaesthetic togeom_parallel_sets_axes()such that color maps to levels of the X axis variables (years in your case). Note that since the nodes don't repeat here (as you would have in different years), the colors are unique for each variable on the X axis.