使用R networkD3软件包中的forceNetwork函数显示边缘权重

时间:2020-04-25 09:34:11

标签: r htmlwidgets networkd3

是否可以使用networkD3::forceNetwork产生的图形上显示边缘权重?

1 个答案:

答案 0 :(得分:0)

Value的{​​{1}}参数是一个字符串,它设置了networkD3::forceNetwork数据框中包含每个链接值的变量/列的名称。该值通常是边缘/链接权重。每个链接的指定变量中的值将确定每个链接的宽度,并显示边缘权重(如果该值所指)。

Links

enter image description here

library(networkD3)
library(tibble)

nodes <- 
  tribble(
    ~name, ~group,
    "a",    1,
    "b",    1,
    "c",    1,
    "d",    1
  )

links <- 
  tribble(
    ~source, ~target, ~value,
    0,       1,       1,
    0,       2,       1,
    0,       3,       1,
  )

forceNetwork(Links = links, Nodes = nodes, Source = "source",
             Target = "target", Value = "value", NodeID = "name",
             Group = "group", opacity = 1)

enter image description here


UPDATE 2020.04.26

这是在链接上添加文本标签的一种方法,以便将鼠标悬停在链接上时显示链接权重的值。

links <- 
  tribble(
    ~source, ~target, ~value,
    0,       1,       1,
    0,       2,       20,
    0,       3,       100,
  )

forceNetwork(Links = links, Nodes = nodes, Source = "source",
             Target = "target", Value = "value", NodeID = "name",
             Group = "group", opacity = 1)

enter image description here

相关问题