Ordering of the nodes
Opened this issue · 3 comments
I am unable to change the ordering of the nodes. Would be great if it is possible when I do ordinal variables and pre/post visualizations.
I am facing the same problem, and I found a partial solution: You can order the node
and next_node
variables of your long format table by setting them as factor and order the associated levels. Example:
df <- data.frame(expand.grid(LETTERS[1:3],LETTERS[1:3]))
set.seed(125)
df$N <- sample(1:10,size = nrow(df),replace = T)
dflong <- df %>%
# arrange(Var1)%>%
make_long(Var1, Var2,value = N)
dflong %>%
ggplot( aes(x = x,
next_x = next_x,
node = node,
next_node = next_node,
fill = factor(node),
value = value)) +
geom_sankey()
dflong$node <- factor(dflong$node,levels = c("C","B","A"))
dflong$next_node <- factor(dflong$next_node,levels = c("C","B","A"))
dflong %>%
ggplot( aes(x = x,
next_x = next_x,
node = node,
next_node = next_node,
fill = factor(node),
value = value)) +
geom_sankey()
You can then tweak the colors if you want
Based on this:
Would it be possible to minimize overlap by arranging the nodes based on their shared proportions? So that the biggest flows are just beside each other?
See this example:
#15
Here "Stocks" share the biggest amount with "Giro" and should be better on the bottom, "Rent" shares the biggest amount with "Shared" and should be on top.
Here the expected, following the factoring-approach:
I also have the same issue, that the sorted order of the node labels needs to be changed to minimise crossing of flows.
Here is the same issue for dhe D3 package : https://stackoverflow.com/questions/37302958/d3-sankey-minimize-link-crossing