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?

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
"Graphviz support is an integral part of the DiagrammeR package" rich-iannone.github.io/DiagrammeR/graphviz_and_mermaid.html You did not show the complete source, but it looks like a Graphviz result
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.
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."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.