问题描述
我试图借助此页面生成Sankey图: https://www.r-graph-gallery.com/321-introduction-to-interactive-sankey-diagram-2.html
现在,我稍稍修改了数据,想知道我是否可以向右和向左下沉节点,即,顶部节点始终在左侧(对齐),而最后节点始终在右侧。看来networkd3仅具有完全正确的选项。
使用以下代码:
library(networkD3)
library(dplyr)
# A connection data frame is a list of flows with intensity for each flow
links <- data.frame(
source=c("group_A","group_B","group_C","group_C"),target=c("group_D","group_F","group_G"),value=c(3,4,3,1)
)
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),as.character(links$target)) %>% unique()
)
# With networkD3,connection must be provided using id,not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source,nodes$name)-1
links$IDtarget <- match(links$target,nodes$name)-1
# Make the Network
p <- sankeyNetwork(Links = links,Nodes = nodes,Source = "IDsource",Target = "IDtarget",Value = "value",NodeID = "name",fontSize=20)
p
给我这个输出:
看起来已经很有希望,但是我想将group_A移到左侧(同时保持右侧对齐)。这可能吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)