2

In DiagrammeR, I would like to pass a valid graph specification string in the DOT language to grViz() that will force a straight edge from node a0 to a1 when there is a separate edge branching off to b0. b0 will be larger than a0 so how do I align a0 and b0 on the same rank where the top of b0 is level with the top of a0?

Current graph specification:

library(DiagrammeR)
grViz("
  digraph G {
    
    node [shape=box];
    a0; a1;
    b0[height=1,width=2];
    node [shape = point, width = 0, height = 0];
    y1;
    
    a0 -> y1 [arrowhead=none];
    y1 -> a1;
    y1 -> b0;

    {rank=same; a0; b0;}
 
  }
")

Current output:

enter image description here

Desired output:

enter image description here

1 Answer 1

3

b0 is different size, so had to change to rankdir=LR to put b0 in its own (vertical) rank.
Then placed a0, a1 and y1 in their own rank

digraph G {
    rankdir=LR  // b0 is larger, so place in a different rank

    node [shape=box];
    {rank=same
      a0; a1;
      y1 [shape = point, width = 0, height = 0];
    }
    b0[height=1.5,width=2];
    
    a0 -> y1 [arrowhead=none];
    y1 -> a1;
    y1 -> b0; 
}

Giving:
enter image description here

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

9 Comments

If I want to add a1 -> {a2, a3}, how would I specify the layout so that these two additional boxes are displayed vertically below a1, but horizontally side by side?
Wait. How do you run this code? In R?
@Onyambu - this is a dot (Graphviz) (graphviz.org) program
@SRL where do you want a2 & a3 in relationship to b0?
@Onyambu : given the tags likely the user is using DiagrammeR::grViz, but yes R and diagrammer are not relevant here to the question or answer. But at the same time many R users of these packages do not realise they are using graphviz. Also diagrammer does not offer complete graphviz correspondence, which sometimes can be relevant t the question.
|

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.