6

The following code creates a flowchart in R with the DiagrammeR package. How can I add "Yes" or "No" (or any other text) to the flowlines connecting the shapes? When creating charts, my nodes will often be decisions, and I'd like to label the flowline answer as Yes/No.

library(DiagrammeR)

grViz("
digraph boxes_and_circles {

      # a 'graph' statement
      graph [overlap = true, fontsize = 10]

      # several 'node' statements
      node [shape = box,
      fontname = Helvetica]
      A; B; C; D; E; F

      node [shape = circle,
      fixedsize = true,
      width = 0.9] // sets as circles
      1; 2; 3; 4; 5; 6; 7; 8

      # several 'edge' statements
      A->1 B->2 B->3 B->4 C->A
      1->D E->A 2->4 1->5 1->F
      E->6 4->6 5->7 6->7 3->8
      }
      ")

Capture.png

stackinator
  • 5,429
  • 8
  • 43
  • 84

1 Answers1

6

Try to define the label for each flowline, like this:

library(DiagrammeR)

grViz("
      digraph boxes_and_circles {

      # a 'graph' statement
      graph [overlap = true, fontsize = 10]

      # several 'node' statements
      node [shape = box,
      fontname = Helvetica]
      A; B; C; D; E; F

      node [shape = circle,
      fixedsize = true,
      width = 0.9] // sets as circles
      1; 2; 3; 4; 5; 6; 7; 8

      # several 'edge' statements
      A->1 [label='YES']
      B->2 [label='NO'] 
      B->3 [label='...'] 
      B->4 C->A
      1->D E->A 2->4 1->5 1->F
      E->6 4->6 5->7 6->7 3->8
      }
")

Hope it helps! :)

tk3
  • 990
  • 1
  • 13
  • 18