0

I am using the visNetwork package to graph certain flows within a shiny app. But I have the problem that the nodes are located in a disorderly way one on top of the other, I have read inside the library documentation but I have not found a parameter to specify the distance between nodes. I would appreciate any help or suggestion.

what i want : What I want is for the nodes to appear separated from each other, without overlapping so that the diagram looks organized.

Thank you


nodes <- structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
29, 30, 31), level = c(1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 7, 8, 
8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 12, 12, 13, 14, 
14), label = c("senectus accumsan maecenas risus est.", "amet tortor aliquam semper class metus", 
"amet tortor aliquam semper class metus", "id, efficitur quisque. Lacus nibh tellus", 
"senectus accumsan maecenas risus est.", "id, efficitur quisque. Lacus nibh tellus", 
"Curae interdum sociis in vel laoreet cum", "urna ad in.", "lorem sodales enim. Ut dictum, blandit", 
"libero tincidunt, enim donec. Vitae", "id, efficitur quisque. Lacus nibh tellus", 
"donec ac porta. A cum cubilia aliquet", "id, efficitur quisque. Lacus nibh tellus", 
"libero tincidunt, enim donec. Vitae", "id, efficitur quisque. Lacus nibh tellus", 
"id, efficitur quisque. Lacus nibh tellus", "Lorem ipsum dolor sit amet, ex posuere", 
"donec ac porta. A cum cubilia aliquet", "lorem sodales enim. Ut dictum, blandit", 
"et penatibus. Libero imperdiet congue", "et penatibus. Libero imperdiet congue", 
"Curae interdum sociis in vel laoreet cum", "non porta erat ante. Donec efficitur eu", 
"lorem sodales enim. Ut dictum, blandit", "donec ac porta. A cum cubilia aliquet", 
"libero tincidunt, enim donec. Vitae", "senectus accumsan maecenas risus est.", 
"sed in posuere curabitur, vitae nibh", "sed in posuere curabitur, vitae nibh", 
"non porta erat ante. Donec efficitur eu", "amet tortor aliquam semper class metus"
), shape = c("circle", "diamond", "circle", "diamond", "circle", 
"circle", "diamond", "circle", "circle", "circle", "circle", 
"diamond", "circle", "circle", "circle", "circle", "circle", 
"circle", "diamond", "diamond", "circle", "circle", "circle", 
"circle", "circle", "diamond", "circle", "circle", "diamond", 
"circle", "circle"), color.background = c("#FFDC5C", "white", 
"white", "white", "white", "white", "white", "white", "white", 
"white", "white", "white", "white", "white", "white", "white", 
"white", "white", "white", "white", "white", "white", "white", 
"white", "white", "white", "white", "white", "white", "white", 
"white"), font.color = c("black", "black", "black", "black", 
"black", "black", "black", "black", "black", "black", "black", 
"black", "black", "black", "black", "black", "black", "black", 
"black", "black", "black", "black", "black", "black", "black", 
"black", "black", "black", "black", "black", "black"), font.size = c(60, 
60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 
60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60), is.terminal = c(FALSE, 
FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, 
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, 
TRUE, TRUE)), row.names = c(NA, 31L), class = "data.frame")

edges <- structure(list(from = c(1, 2, 2, 4, 4, 6, 7, 7, 9, 9, 8, 10, 
10, 12, 12, 13, 13, 14, 15, 16, 17, 19, 19, 20, 20, 21, 26, 26, 
27, 28, 29, 29), to = c(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15, 16, 17, 18, 19, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
29, 29, 30, 31), length = c(100, 600, 600, 600, 600, 100, 600, 
600, 600, 600, 100, 600, 600, 600, 600, 600, 600, 100, 600, 600, 
100, 600, 600, 600, 600, 100, 600, 600, 600, 600, 600, 600), 
    label = c(NA, "NO", "SI", "SI", "NO", NA, "SI", "NO", "NO", 
    "SI", NA, "NO", "SI", "SI", "NO", "NO", "SI", NA, NA, NA, 
    "SI", "SI", "NO", "SI", "NO", NA, "SI", "NO", NA, NA, "SI", 
    "NO"), font.size = c(40, 40, 40, 40, 40, 40, 40, 40, 40, 
    40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 
    40, 40, 40, 40, 40, 40, 40, 40)), row.names = c(NA, 32L), class = "data.frame")


visNetwork(nodes,edges, width = "100%") %>%
     visPhysics(stabilization = TRUE, enabled = TRUE) %>%
     visHierarchicalLayout( levelSeparation = 1000, nodeSpacing = 9000, blockShifting = FALSE, treeSpacing = 10000) %>%
    # #visOptions(highlightNearest = list(enabled = T, degree = 1, hover = F), autoResize = TRUE, collapse = FALSE) %>%
     visEdges(color = list(highlight = "red")) %>%  

     visLayout(improvedLayout = TRUE) %>%
     visEdges(arrows = edges$arrows) %>%
     #visInteraction(multiselect = F) # %>%
     visEvents(doubleClick = "function(nodes) {Shiny.onInputChange('current_node_id', nodes.nodes);;}") %>% 
     visEvents(stabilizationIterationsDone="function () {this.setOptions( { physics: false } );}")

MatCordTo
  • 223
  • 1
  • 7
  • It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jun 13 '22 at 20:14
  • Hey thanks for your commetn i already edit the question, I would appreciate your help – MatCordTo Jun 14 '22 at 01:58

0 Answers0