R:显示“;弹出窗口“;鼠标悬停在(图形)网络上时的信息

R:显示“;弹出窗口“;鼠标悬停在(图形)网络上时的信息,r,graph,popup,igraph,visnetwork,R,Graph,Popup,Igraph,Visnetwork,我模拟了一些数据,并使用visnetwork在R中创建了一个图形网络: library(igraph) library(dplyr) library(visNetwork) #create file from which to sample from x5 <- sample(1:100, 1100, replace=T) #convert to data frame x5 = as.data.frame(x5) #create first file (take a random sa

我模拟了一些数据,并使用visnetwork在R中创建了一个图形网络:

library(igraph)
library(dplyr)
library(visNetwork)

#create file from which to sample from
x5 <- sample(1:100, 1100, replace=T)
#convert to data frame
x5 = as.data.frame(x5)

#create first file (take a random sample from the created file)
a = sample_n(x5, 1000)
#create second file (take a random sample from the created file)
b = sample_n(x5, 1000)

#combine
c = cbind(a,b)
#create dataframe
c = data.frame(c)
#rename column names
colnames(c) <- c("a","b")


#create graph
graph <- graph.data.frame(c, directed=F)
graph <- simplify(graph)


plot(graph)
fc <- fastgreedy.community(graph)
V(graph)$community <- fc$membership
library(visNetwork)
nodes <- data.frame(id = V(graph)$name, title = V(graph)$name, group = V(graph)$community)
nodes <- nodes[order(nodes$id, decreasing = F),]
edges <- get.data.frame(graph, what="edges")[1:2]

#visnet graph
visNetwork(nodes, edges) %>%   visIgraphLayout(layout = "layout_with_fr") %>%
    visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)

您要参照的“弹出窗口”在vis网络中称为“工具提示”,它指向节点的(边)标题。更改节点的标题以更改工具提示文本。另外,请查看visInteraction()以更改工具提示行为@user12256545:感谢您的回复!我一直在尝试更改“VisitInteraction”选项,但它似乎不起作用。我会继续尝试。有人知道怎么做吗?你参考的“弹出窗口”在vis网络中称为“工具提示”,它指向节点的(边)标题。更改节点的标题以更改工具提示文本。另外,请查看visInteraction()以更改工具提示行为@user12256545:感谢您的回复!我一直在尝试更改“VisitInteraction”选项,但它似乎不起作用。我会继续努力。有人知道怎么做吗?
#add some information corresponding to the original data

other_damages_in_dollars <- rnorm(1000,104,9)

location <- c("canada","usa")

location <- sample(location, 1000, replace=TRUE, prob=c(0.3, 0.7))

type_of_house <- c("single","townhome", "rental" )

type_of_house<- sample(type_of_house , 1000, replace=TRUE, prob=c(0.5, 0.3, 0.2))

#heres how the original data would have looked like

original_data = data.frame(a,b, other_damages_in_dollars, location, type_of_house)
 #visnet graph - is it possible to use the '$' operator to add these properties?

     visNetwork(nodes, edges) %>%   visIgraphLayout(layout = "layout_with_fr") %>%
        %>%    visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)visEvents(selectEdge = "function(properties) { alert(this.body.data.edges._data[properties.edges[0]].original_data$location); }")  %>%    visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)visEvents(selectEdge = "function(properties) { alert(this.body.data.edges._data[properties.edges[0]].original_data$type_of_house); }")  %>%    visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)visEvents(selectEdge = "function(properties) { alert(this.body.data.edges._data[properties.edges[0]].original_data$other_damage_in_dollars); }")