datastorm-open / visNetwork

R package, using vis.js library for network visualization
Other
542 stars 127 forks source link

Edges overlay, making one of the labels not visible. #441

Open ischlo opened 2 years ago

ischlo commented 2 years ago

Hello ! thanks for the great package to visualize networks. I noticed a detail that could improve readability of the output. When you have two nodes in a directed network with each having a edge towards the other, the edges are visualized on top of each other and in the case when they have different labels, one ends up masked by the other. Is there a way around this currently ? or might be a nice improvement for the future.

Here is the example I was working on: Nodes B and C have each an edge towards the other and it would be cool to have them split so that the respective weights are visible.

nodes1 <- data.frame(id = c("A","B","C","D","E")
                    ,label = c("A","B","C","D","E"))
edges1 <- data.frame(from = c("A","A","B","C","B","C","C","D","E")
                    ,to =   c("B","C","C","B","D","D","E","E","D")
                    ,label = c(10,3,1,4,2,8,2,7,9)
                    #,arrows =
                    )
visNetwork(nodes1
           ,edges1
           ,width = "100%")  %>% 
  visEdges(shadow = FALSE
           ,arrows = "to"
           ,smooth = TRUE
           ,color = list(color = "lightblue"
                         ,highlight = "red")
           ,physics = FALSE
           ) %>%
  visNodes(physics = FALSE
           ,shape = "ellipse") %>% 
  visLayout(improvedLayout = TRUE) %>% 
  visOptions(collapse = FALSE
             ,manipulation = FALSE
             ,height = "100%"
             )

best, Ivann