使用visNetwork

时间:2016-09-28 22:47:44

标签: r graph

我开始了解R中的交互式图形,我发现库visNetwork非常有帮助。

但是,当鼠标移到边缘时,我不会在小插图中找到如何显示弹出窗口,其中包含的信息比valuetitle更多。

使用文档中的一个示例

# data used in visNetwork vignette
nb <- 10
nodes <- data.frame(id = 1:nb, label = paste("Label", 1:nb),
group = sample(LETTERS[1:3], nb, replace = TRUE), value = 1:nb,
title = paste0("<p>", 1:nb,"<br>Tooltip !</p>"), stringsAsFactors = FALSE)

edges <- data.frame(from = c(8,2,7,6,1,8,9,4,6,2),
to = c(3,7,2,7,9,1,5,3,2,9),
value = rnorm(nb, 10), label = paste("Edge", 1:nb),
title = paste0("<p>", 1:nb,"<br>Edge Tooltip !</p>"))

visNetwork(nodes, edges, height = "500px", width = "100%") 

如何在弹出窗口中添加更多信息,例如与边缘相关的不同参数(宽度,频率,......)?

1 个答案:

答案 0 :(得分:3)

您必须将所有信息粘贴到标题栏中。

# data used in visNetwork vignette
nb <- 10
nodes <- data.frame(id = 1:nb, label = paste("Label", 1:nb),
                    group = sample(LETTERS[1:3], nb, replace = TRUE), value = 1:nb,
                    title = paste0("<p>", 1:nb,"<br>Tooltip !</p>"), stringsAsFactors = FALSE)

edges <- data.frame(from = c(8,2,7,6,1,8,9,4,6,2),
                    to = c(3,7,2,7,9,1,5,3,2,9),
                    value = rnorm(nb, 10), label = paste("Edge", 1:nb))

edges$title <- paste0(edges$label, "<br> value : ", round(edges$value, 2))

visNetwork(nodes, edges, height = "500px", width = "100%")