0

I'm making a graph with DiagrammeR and I'm having problems with some of the nodes overlapping. The (relevant) code looks like this (I ommited some irrelevant parts regarding color aesthetics, fontsizes, and more):

library(DiagrammeR)

nodes <- create_node_df(
  n = 39,
  type = "numbered",
  label = c("Espacial", "Aeronáutica", "Nuclear", "Automotriz", "Minería", "Petróleo\ny gas", "Electrónica", "Defensa", "Metal-\nmecánica", "Náutica", "Agricultura", "Telecomu-\nnicaciones", 1:27),
  width = c(rep(0.7825, 12), rep(0.2, 27)),
  height = c(rep(0.7825, 12), rep(0.2, 27)),
)

edges <- create_edge_df(
  from = c(rep(13, 6), rep(14, 2), 15, 16, 17, rep(18, 4), 19, rep(20, 3), rep(21, 5), 22, rep(23, 2), rep(24, 5), rep(25, 3), rep(26, 3), rep(27, 2), rep(28, 3), rep(29, 2), rep(30, 3), rep(31, 2), rep(32, 3), rep(33, 3), rep(34, 2), rep(35, 3), rep(36, 5), 37, 38, rep(39, 5)),
  to = c(1, 2, 3, 4, 5, 6, 1, 2, 1, 7, 7, 1, 2, 3, 4, 7, 1, 2, 6, 1, 2, 3, 7, 8, 6, 1, 2, 1, 2, 4, 7, 8, 1, 2, 4, 1, 3, 4, 1, 9, 1, 4, 10, 1, 6, 1, 4, 9, 1, 3, 1, 11, 12, 1, 6, 7, 1, 3, 1, 2, 6, 1, 5, 6, 8, 11, 7, 1, 1, 2, 3, 4, 8),
  arrowhead = "none"
)

graph <- create_graph(nodes_df = nodes, edges_df = edges)

render_graph(graph)

And this is the output: enter image description here

Does anybody know how can I avoid nodes overlapping, without having to manually position them?

Gaspar
  • 49
  • 1
  • 8

2 Answers2

0

Try overlap=false (https://www.graphviz.org/docs/attrs/overlap/) at the graph-level

sroush
  • 5,375
  • 2
  • 5
  • 11
  • Thank your for your response. I'm afraid I didn't quite understang where to add `overlap = F`. Note that I'm actually using `DiagrammeR` and not `Graphviz`. Sorry if I didn't state that clearly. – Gaspar Mar 15 '23 at 22:42
  • "Graphviz support is an integral part of the DiagrammeR package" https://rich-iannone.github.io/DiagrammeR/graphviz_and_mermaid.html You did not show the complete source, but it looks like a Graphviz result – sroush Mar 15 '23 at 22:53
  • Thank you very much for the site, seems very good. I know that grViz is part of DiagrammeR but the syntax seems to be quite different, and I wouldn't know what to add (and where) in order to avoid overlapping in my current code. – Gaspar Mar 16 '23 at 15:00
0

What helped me with an analogous problem was adding the following:

%>%
  add_global_graph_attrs(
  attr = "overlap",
  value = "false",
  attr_type = "graph")

(after my "create_graph() %>%" statement).

I got this from the manual: https://cran.r-project.org/web/packages/DiagrammeR/DiagrammeR.pdf

by searching the word "overlap."

p365
  • 1
  • 1