代码之家  ›  专栏  ›  技术社区  ›  firmo23

函数的作用是:当边超过一个时,在节点之间重叠边

  •  0
  • firmo23  · 技术社区  · 7 年前

    我有下面的代码,它使用r包可视化网络 visNetwork .

    library(visNetwork)                  
      id<-c("articaine","benzocaine","etho","esli")
      label<-c("articaine","benzocaine","etho","esli")
      node<-data.frame(id,label)
    
      from<-c("articaine","articaine","articaine","articaine","articaine","articaine","articaine","articaine","articaine")
      to<-c("benzocaine","etho","esli","benzocaine","etho","esli","benzocaine","etho","esli")
      title<-c("SCN1A","SCN1A","SCN1A","SCN2A","SCN2A","SCN2A","SCN3A","SCN3A","SCN3A")
    
      edge<-data.frame(from,to,title)
    
      visNetwork(nodes = node,edge)%>% 
    
    
        visOptions(highlightNearest=T, nodesIdSelection = T) %>%
    
        # Specify that hover interaction and on-screen button navigations are active
        visInteraction(hover = T, navigationButtons = T) %>%
    
    
        visIgraphLayout(randomSeed = 997)
    

    如果删除最后一行

    %>%
    
    
            visIgraphLayout(randomSeed = 997)
    

    网络可视化是正确的

    enter image description here

    但是当我加进去的时候,我失去了一些边缘。

    enter image description here

    我需要 visIgraphLayout() 功能,因为它使我真正的网络看起来更好,也复制得更快。为什么会这样?可能的解决方案?

    0 回复  |  直到 7 年前
        1
  •  1
  •   JAIP    6 年前

    折衷方法是将平滑特性指定给具有多条边的from-to组合,而不是其他组合。在我看来,这大大提高了绘图的速度。顺便说一下,我正在使用data.table和visNetwork。

    ##assign smooth property where multiple edges
    edge_list[, N := .N, by = c("from", "to")]
    edge_list[N > 1, smooth := T]
    edge_list[N == 1, smooth := F]
    
    ##plot
    visNetwork(nodes = node_list,
               edges = edge_list[, .(from, to, smooth)]) %>%
    visNodes(physics = F) %>%
    visIgraphLayout(randomSeed = 951)
    

    很抱歉这个例子不可复制,但希望有用。