简体   繁体   English

具有重复“to”和“from”节点名称的 Highcharter Sankey 图

[英]Highcharter Sankey diagram with repeated "to" and "from" node names

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:不幸的是,highcharter 尝试使用单个节点并使边缘来回移动:

# 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")

重复“to”和“from”节点的桑基图

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 (eg prepending "to " to each of them), but I would like to keep the same names and have the colours match.我已经使用了解决方法或重命名了“to”节点,这样它们就不会共享名称(例如,在每个节点前面加上“to”),但我想保持相同的名称让颜色匹配。

# extra data preparation step for partial workaround
flows$to <- paste("to", flows$to)

名称不同,颜色不匹配

I had the same trouble and it was very frustrating.我遇到了同样的麻烦,这非常令人沮丧。 The only way that worked relatively well for me was, following your approach, generating white space before the names in the "to" column, like this:对我来说效果相对较好的唯一方法是,按照您的方法,在“to”列中的名称之前生成空格,如下所示:

data %>% data_to_sankey() %>% mutate(to = paste(" ", to)) %>% hchart(type = "sankey")

I hope this can help you.我希望这可以帮助你。

Thank you!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM