Search code examples
rdiagrammer

DiagrammeR How can I left align text in nodes using HTML


How can I left-align text in DiagrammeR::graphviz() when I use HTML code?

I need to insert bullet points, venus and mars signs into the nodes, and I have only been able to do this using HTML.

I can find several posts describing how to left-align when not using HTML (\\l), but I can't find any posts on how to do it using HTML.

How can I left-align the text in the nodes when using HTML?

Reprex:

```{r}
DiagrammeR::grViz("
digraph rmarkdown{

# Box
node [shape = box
     fontname = Helvetica,
     penwidth = 1.0,
     fixedsize = true,
     width = 3,
     height = 1]

A;

A[label = 
<
Top row<br/> 
&#8226; Bullet one<br/> 
&#8226; Bullet two with more words<br/>
&#9792; A venus sign
>]
}
")
```

enter image description here


Solution

  • I found an answer here: https://www.graphviz.org/doc/info/shapes.html

    You need to insert the line ALIGN = 'LEFT' in the HTML line break code.

    See below:

    DiagrammeR::grViz("
    digraph rmarkdown{
    
    # Box
    node [shape = box]
    
    A;
    
    A[label = 
        <
        Top row<br ALIGN = 'LEFT'/> 
        &#8226; Bullet one<br ALIGN = 'LEFT'/> 
        &#8226; Bullet two with more words<br ALIGN = 'LEFT'/>
        &#9792; A venus sign <br ALIGN = 'LEFT' />
        >
    ]
    
    }
    ")
    ```
    

    enter image description here