0

the following image shows one of my sankey diagrams:

Sankey Diagram with a lot of labels

As you can see, I do have a lot of labels shown. I know I can disable the labels completely, however, I am interested to know if I can also choose only specific labels I would like to display (either based on ID of the node or the value of path traversals or on something else). Has anyone played around with that yet and could give me a hint?

4

1 回答 1

0

节点标签来自您传递给函数NodeID的数据框中的 's 。Nodes这些 ID/标签中的任何一个都可以是空白字符串"",这将有效地使关联节点的标签不可见。

使用帮助文件的示例,这将打印每个节点的标签...

URL <- paste0('https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json')
energy <- jsonlite::fromJSON(URL)

sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = 'source',
              Target = 'target', Value = 'value', NodeID = 'name',
              units = 'TWh', fontSize = 12, nodeWidth = 30)

而这不会为左上角的三个“石油”节点打印标签......

URL <- paste0('https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json')
energy <- jsonlite::fromJSON(URL)

energy$nodes[37:39, ] <- ' '

sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = 'source',
              Target = 'target', Value = 'value', NodeID = 'name',
              units = 'TWh', fontSize = 12, nodeWidth = 30)

但是,当标签/ s 与数据框中的和idNodeID不匹配时要小心……在这种情况下(如上面的示例中),该函数依赖于数据框中 id 的顺序来关联它们。SourceTargetLinkssankeyNetwork()

于 2017-03-15T14:04:54.807 回答