我正在尝试建立链接的对象的交互式网络可视化。我已经审查了代码:https://christophergandrud.github.io/networkd3/
,但无法找到一个代码示例,该示例可以帮助我将节点转换为可点击的URL,以重定向用户或将启动新的浏览器窗口。这可能吗?我的问题与使用此代码示例保存为HTML的networkD3
图表有关:
library(networkD3)
library(magrittr)
Source <- c("A", "A", "A", "A", "B", "B", "C", "C", "D")
Target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
NetworkData <- data.frame(Source, Target)
simpleNetwork(NetworkData) %>% saveNetwork(file = 'Net1.html')
您需要使用forceNetwork()
功能以获得该功能,再加上一些额外的工作。
(示例主要基于 @timelyportfolio的代码:使用clickAction = netchaction = null = null链接到网站上的节点(
library(networkD3)
library(magrittr)
data(MisLinks)
data(MisNodes)
fn <- forceNetwork(
Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4, zoom = TRUE
)
fn$x$nodes$hyperlink <- paste0(
'http://en.wikipedia.org/wiki/Special:Search?search=',
MisNodes$name
)
fn$x$options$clickAction = 'window.open(d.hyperlink)'
fn %>% saveNetwork(file = 'Net1.html')