Using visNetwork to dynamically update nodes in R

前端 未结 2 896
轮回少年
轮回少年 2021-01-26 13:22

the below snapshot visual is created using the \"visNetwork\" package. My requirement here is that I have to hard code the edges and also after using visHierarchicalLayout(), I

2条回答
  •  执笔经年
    2021-01-26 13:42

    If I understand your question correctly, you want to create the edges data frame based on the id in the nodes data frame. Here is one option.

    # Extract the id
    num <- nodes$id
    
    # Repeat the numbers
    num2 <- rep(num, each = 2)
    
    # Remove the first and last numbers
    num3 <- num2[c(-1, -length(num2))]
    
    # Create a data frame
    edges <- as.data.frame(matrix(num3, ncol = 2, byrow = TRUE))
    names(edges) <- c("from", "to")
    
    edges
    #   from to
    # 1    1  2
    # 2    2  3
    # 3    3  4
    # 4    4  5
    # 5    5  6
    # 6    6  7 
    

提交回复
热议问题