Search code examples
rgraphvisnetwork

why doesn't this visNetwork in R show edge


I'm exploring visNetwork and can't figure out why this one doesn't show edge

library(visNetwork)
nodes=data.frame(node=c('m1','m2','n1','n2'))
a=data.frame(x=c('n1','n2'),y=c('m1','m2'))
links=a%>% group_by(x,y)%>%tally()
visNetwork(nodes, links)

Solution

  • From ?visNetwork:

    nodes: data.frame with nodes informations. Needed at least column "id".
    edges: data.frame with edges informations. Needed at least columns "from" and "to".

    So

    visNetwork(
      setNames(nodes, "id"),
      setNames(links, c("from", "to", "foo"))
    ) 
    

    will work.