0

Q: In DiagrammeR native syntax, how does one force certain nodes to be on the same rank?

E.g., below I was able to force nodes 4, 5, 6, 7 onto the same rank by creating an invisible node 2, with invisible edges in and out of it. But this is just a hack. And the resulting diagram is a little off balance. There must be a better way to do this, right?

library(DiagrammeR)

g <- create_graph(attr_theme="tb")
g <- add_node(g) # node 1
g <- add_node(g, from=1, node_aes = node_aes(style = "invisible"), edge_aes = edge_aes(style = "invisible", arrowhead = "none")) # node 2, my invisible node
g <- add_node(g, from=1, edge_aes = edge_aes(style = "solid")) # node 3
g <- add_node(g, from=2, edge_aes = edge_aes(style = "invisible", arrowhead = "none")) # node 4
g <- add_node(g, from=2, edge_aes = edge_aes(style = "invisible", arrowhead = "none")) # node 5
g <- add_edge(g, from=1,to=4, edge_aes = edge_aes(style = "solid"))
g <- add_edge(g, from=1,to=5, edge_aes = edge_aes(style = "solid"))
g <- add_node(g, from=3) # node 6
g <- add_node(g, from=3) # node 7
render_graph(g)

enter image description here

lowndrul
  • 3,715
  • 7
  • 36
  • 54
  • This surely sounds like a duplicate of your other question. – IRTFM Sep 02 '23 at 19:39
  • @IRTFM I think you mean my question [How to adjust position of single node in flow diagram in DiagrammeR?](https://stackoverflow.com/q/77029460/629000). Def not a duplicate. There, ultimately, I want to place the entire diagram within a single node, by adjusting the node size and location. Here, I really just want to get these nodes on the same rnak. – lowndrul Sep 02 '23 at 20:49

0 Answers0