从visNetwork可视化中删除节点和边缘标签,并在单击节点和边时显示信息

时间:2018-02-21 20:15:36

标签: r igraph visnetwork

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

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

1 个答案:

答案 0 :(得分:0)

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

<块引用>

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

我想您可以通过调整 title 中的 html 来实现您在 3 中的愿望,就像我在下面所做的那样。

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))