I am trying to visualise migration data with a Sankey diagram, in which names of nodes will be repeated between the "from" and "to" columns of the data frame. Unfortunately, highcharter tries to use single nodes and makes the edges go back and forth:
# import and prepare the data
flows <- read.table("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/13_AdjacencyDirectedWeighted.csv",
header = TRUE,
check.names = FALSE)
flows$from <- rownames(flows)
library(tidyr)
flows <- flows %>%
pivot_longer(-from, names_to = "to", values_to = "weight")
# visualise
library(highcharter)
hchart(flows, "sankey")
How would one force the nodes to be placed on two separate columns, while keeping the same colour for each area/continent?
I have used the workaround or renaming the "to" nodes so they don't share names (e.g. prepending "to " to each of them), but I would like to keep the same names and have the colours match.
# extra data preparation step for partial workaround
flows$to <- paste("to", flows$to)