Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Justify node text in DiagrammeR

Tags:

r

diagrammer

Does anybody know if DiagrammeR currently supports left- and right-justification of node labels when using GraphViz?

Here is a quick example, where I would like to left-justify the text within both of the nodes:

library(DiagrammeR)
grViz("
  digraph test {
    graph [fontsize = 10]

    node [shape = box]
    A [label = 'Foo\nBar']
    B [label = 'Bar\nFoo']

    A -> B
  }
")

I was able to find one resource here for the native GraphViz that uses /l for left-justification, but when I try that within the grViz function I receive an error. For example:

library(DiagrammeR)
grViz("
digraph test {
  graph [fontsize = 10]

  node [shape = box]
    A [label = 'Foo\lBar']
    B [label = 'Bar\lFoo']

  A -> B
}
")

I appreciate any help in advance!

like image 417
Derek Damron Avatar asked Sep 16 '25 07:09

Derek Damron


1 Answers

You need a double backslash to escape the first slash. Here are left and right justified labels:

grViz("
  digraph test {
    graph [fontsize = 10]

    node [shape = box]
    A [label = 'Foo\\lBar\\l']
    B [label = 'Bar\\rFoo\\r']

    A -> B
  }
")
like image 120
eipi10 Avatar answered Sep 17 '25 23:09

eipi10