datastorm-open / visNetwork

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

Prevent Overlapping Edges #434

Closed gfleetwood closed 2 years ago

gfleetwood commented 2 years ago

Hi,

I'm trying to fix an issue with overlapping edges and can't find an option to solve my problem. I'm using visNetwork 2.0.9 with R 3.6.3 on Ubuntu 20.04.

This is my data:

name,reports_to
Francoise,Catherine
Elisa,Bob
Gerhard,Francoise
Bob,Anne
Catherine,Anne
Anne,NONE
Dave,Bob

This is my code:

library(tidyverse)
library(visNetwork)

t <- read_csv("t.csv") %>% 
  filter(reports_to != "NONE")

a = t %>% unlist() %>% unname() %>% unique()

nodes <- data.frame(label = a, id = 1:length(a))

edges <- t %>%
  inner_join(nodes, by = c("name" = "label")) %>% 
  rename(from = id) %>%
  inner_join(nodes, by = c("reports_to" = "label")) %>% 
  rename(to = id) %>% 
  select(from, to)

visNetwork(nodes, edges, main = "Org Chart") %>%
  visEdges(arrows = "to") %>% 
  visHierarchicalLayout(sortMethod = "directed", direction = "DU")

And this is the output where the edges to Bob overlap with the edge to Catherine. That's what I want to prevent.

Rplot