1

我使用 visNetwork 来可视化我的网络。下面是代码(借自 visNetwork cran 页面)。我的问题是:

  1. 我不会显示顶点和边缘标签。如何从可视化中删除它?
  2. 我想在单击节点时显示节点信息。当我单击任何节点和边时,似乎显示了数据标题列中的任何内容。标题是点击信息显示的“保留”列名吗?
  3. 当我点击任何节点时,我几乎看不到任何东西。如何更改点击显示的字体?非常感谢。

library(igraph)
library(visNetwork)
nodes <- data.frame(id = 1:10, 
    label = paste("Node", 1:10),                                 
    group = c("GrA", "GrB"),                                     
    value = 1:10,                                               
    shape = c("square", "triangle", "box", "circle", "dot", "star",
    "ellipse", "database", "text", "diamond"),                   
    title = paste0("<p><b>", 1:10,"</b><br>", paste("Node", 1:10),"</p>"), 
    color = c("darkred", "grey", "orange", "darkblue", "purple"),
    shadow = c(FALSE, TRUE, FALSE, TRUE, TRUE))                  



    edges <- data.frame(from = sample(1:10, 8), to = sample(1:10, 8),
    label = paste("Edge", 1:8),                                 
    length = c(100,500),                                        
    arrows = c("to", "from", "middle", "middle;to"),           
    dashes = c(TRUE, FALSE),                                    
    title = paste("Edge", 1:8),                                 
    smooth = c(FALSE, TRUE),                                    
    shadow = c(FALSE, TRUE, FALSE, TRUE))                       


 g <- graph_from_data_frame(d = edges, vertices = nodes)
 visIgraph(g)
4

1 回答 1

0

您可以使用参数完成 1. font.size(见下文)。关于 2. 和 3.,用于读取的visNodes文档title

默认为未定义。当用户将鼠标悬停在节点上时显示的标题。标题可以是 HTML 元素或包含纯文本或 HTML 的字符串。

我想你可以通过调整其中的 html 来完成你在 3 中想要的,title就像我在下面所做的那样。

nodes <- data.frame(id = 1:10, 
                    label = paste("Node", 1:10),                                 
                    group = c("GrA", "GrB"),                                     
                    value = 1:10,                                               
                    shape = c("square", "triangle", "box", "circle", "dot", "star",
                              "ellipse", "database", "text", "diamond"),                   
                    title = paste0("<p><b style='font-size: 40px'>", 1:10,"</b><br>", paste("Node", 1:10),"</p>"), 
                    color = c("darkred", "grey", "orange", "darkblue", "purple"),
                    shadow = c(FALSE, TRUE, FALSE, TRUE, TRUE),
                    font.size = c(0, 0, 0, 0, 0))                  

edges <- data.frame(from = sample(1:10, 8), to = sample(1:10, 8),
                    label = paste("Edge", 1:8),                                 
                    length = c(100,500),                                        
                    arrows = c("to", "from", "middle", "middle;to"),           
                    dashes = c(TRUE, FALSE),                                    
                    title = paste("Edge", 1:8),                                 
                    smooth = c(FALSE, TRUE),                                    
                    shadow = c(FALSE, TRUE, FALSE, TRUE),
                    font.size = c(0, 0, 0, 0)) 
于 2021-01-07T14:17:55.580 回答