rvisnetwork

Remove self-loop in visNetwork


I want to remove the self-loop in visNetwork, how can I do it?

library(visNetwork)
nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))
visNetwork(nodes, edges, width = "100%")

enter image description here

I tried to add the following code, but it still did not work.

edges$value = 1
edges$value = ifelse(edges$from == edges$to, 0, edges$value)

Solution

  • We can remove edges where from is same as to before plotting:

    library(visNetwork)
    
    visNetwork(nodes = nodes, edges = edges[ edges$from != edges$to, ])
    

    enter image description here