Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

diagrammeR specifying node order and formatting text

Tags:

r

diagrammer

I am using diagrammeR grViz to construct a flow chart. I would like to specify the order of some of the nodes that have the same rank. In the following chart, I would like to have Node 1 in the center rather than on the left. In addition, I would like to have "Node 2" underlined, but not "extra detail". Here is the code:

library("DiagrammeR")

grViz(" 
      digraph CFA {
      # Multiple level nodes
      node [shape = rectangle, color=CornflowerBlue]
      a [label = 'Node 1' ]; 

      node [shape = ellipse, color=CornflowerBlue]
      T1    [label = 'Node 2\\nextra detail']; 
      T2    [label = 'Node 3']; 

      {rank = same; a T1 T2}

      # Connect nodes with edges and labels
      a -> T1
      a -> T2
       }


      ")

enter image description here

Any help would be much appreciated. Also, if there are resources to help me along with these customization issues in diagrammeR, please include a link.

like image 825
Steve Avatar asked Jan 18 '18 23:01

Steve


1 Answers

there are several ways to order the nodes. The easiest here is perhaps to have the edge T2 -> a in this order (rather than a -> T2), so node T2 is first and then use dir=back to reverse the arrow. You can use html to underline the node label. (also have to use break, <br/>, instead of newline,\n)

grViz(" 
      digraph CFA {
      a [label = 'Node 1', shape = rectangle, color=CornflowerBlue ]; 

      node [shape = ellipse, color=CornflowerBlue]
      T1    [label = <Node 2 <br/> <u>extra detail</u>>]; 
      T2    [label = 'Node 3']; 

      {rank = same; a T1 T2}

      # Connect nodes with edges and labels
      a -> T1
      T2 -> a[dir=back]
       }

      ")

enter image description here


From comment: Is there a way to make a portion of the text in a node a different color (e.g. just the "extra detail", but not "Node 2")?

Yes, from the html link above you can "sets the color of the font within the scope of FONT.../FONT". So for example, change the label of T1 to

label = <Node 2 <br/> <font color='red'> <u>extra detail</u> </font> >
like image 167
user20650 Avatar answered Nov 06 '22 16:11

user20650