Search code examples
rgraphvizdotdiagrammer

How to add 3 dots in a graphviz network diagram?


I have a simple graphviz network graph where I want to show the neural network architecture of my model:

DiagrammeR::grViz("digraph G {

rankdir = LR

{a b z} -> {x1, x2, x100} -> Y
                  
}")

which outputs to:

enter image description here

Now, I want to add 3 dots (vertically) after b in the first layer and after x2 in the second layer, indicating that there are more nodes in these layers than I can show in a presentation. For example, there is 100 nodes (units) in the second layer (x1, x2 ... x100).

What I want is similar to the 3 dots in this example (taken from this study/source):

enter image description here


Solution

  • There are two challenges

    1. find a way to display the vertical ellipsis (the three dots)
    2. keep the original nodes displayed in the desired order and location

    The following works on my computer if output is SVG, but not png. If SVG is OK by you, here goes. If you need to directly create a png, an embedded image works.

    digraph G {
    rankdir = LR
    splines=false  // straight lines, not curves
    // define ellipsis nodes
    E1[shape=none  label="⋮" fontsize=30]
    E2[shape=none  label="⋮" fontsize=30]
    {rank=same a b E1 z}       // align on same rank
    {rank=same x1 x2 E2 x100}  // align on same rank
    
    {a b z} -> {x1, x2, x100} -> Y
    
    // invisible edges to order nodes
    edge[style=invis]
    a->b->E1->z 
    x1->x2->E2->x100 
    }
    

    Giving (svg converted to png by Imagemagick):
    enter image description here