【问题标题】:igraph/visNetwork with R: How to disable forward linking?带有 R 的 igraph/visNetwork:如何禁用前向链接?
【发布时间】:2018-02-26 03:18:48
【问题描述】:

以下代码生成了一个漂亮的网络图:

library(igraph);library(visNetwork);library(dplyr)

set.seed(123)
nnodes <- 10
nnedges <- 20

nodes <- data.frame(id = 1:nnodes)
edges <- data.frame(from = sample(1:nnodes, nnedges, replace = T),
                    to = sample(1:nnodes, nnedges, replace = T))

visNetwork(nodes, edges) %>%
  visIgraphLayout(layout = "layout_in_circle") %>%
  visNodes(shape="circle") %>% 
  visOptions(highlightNearest = list(enabled = T, hover = T), nodesIdSelection = T)

我的问题是:如何禁用从相邻节点离开的边缘所显示的边缘(例如,选择节点8时,我不希望显示3到9的边缘)。 p >

编辑:添加了库,感谢您指出这一点

【问题讨论】:

  • 由于您的代码同时使用了visNetworkdplyr,因此您也可以包含这些库语句。
  • highlightNearest 选项 algorithm = "hierarchical" 是您要找的吗?
  • 这可能会有所帮助:visNetwork(nodes, edges) %&gt;% visIgraphLayout(layout = "layout_in_circle") %&gt;% visNodes(shape="circle") %&gt;% visOptions(nodesIdSelection = T) %&gt;% visInteraction(hover = T)nodes &lt;- data.frame(id = 1:nnodes, label = 1:nnodes)。它正确突出显示节点,但未使用 hideColor(灰色)。

标签: r igraph visnetwork


【解决方案1】:

使用 Djack 和 wici 的评论,我实现了以下解决方案:

library(igraph);library(visNetwork);library(dplyr)

set.seed(123)
nnodes <- 10
nnedges <- 20

nodes <- data.frame(id = 1:nnodes, label = 1:nnodes)
edges <- data.frame(from = sample(1:nnodes, nnedges, replace = T),
                    to = sample(1:nnodes, nnedges, replace = T))

visNetwork(nodes, edges) %>% 
  visIgraphLayout(layout = "layout_in_circle") %>% 
  visNodes(shape="circle") %>% 
  visOptions(highlightNearest = list(enabled = T, hover = T, algorithm="hierarchical"),nodesIdSelection = T) %>% 
  visInteraction(hover = T) 

我希望,这就是你要找的。​​p>

【讨论】:

    猜你喜欢
    • 2019-06-17
    • 2018-10-24
    • 2022-07-04
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    • 2022-01-26
    • 1970-01-01
    相关资源
    最近更新 更多