我有下面的代码,该代码使用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()
函数,因为它使我的真实网络看起来更好,并且复制速度更快。为什么会发生?可能的解决方案?
答案 0 :(得分: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)
抱歉,该示例不可复制,但希望有用。