0

我有下面的代码,它使用 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)

网络可视化是正确的

在此处输入图像描述

但是当添加时,我失去了一些边缘。

在此处输入图像描述

我需要该visIgraphLayout()功能,因为它使我的真实网络看起来更好,并且复制速度也更快。为什么会发生这种情况?可能的解决方案?

4

1 回答 1

1

一种折衷方案是将平滑属性分配给具有多条边的从到组合,但不分配给其他组合。就我而言,这显着提高了绘图速度。顺便说一句,我正在使用 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)

对不起,不可复制的例子,但希望有用。

于 2019-05-01T12:40:25.343 回答