Flowcharts are a great way to communicate ideas in a vision fashion. The DiagrammerR package and the grViz function provide an open-source solution for the creation of such diagrams. Below is code for an example of a flowchart using lyrics from the nursey rhyme, ‘Twinkle, Twinkle Little Star’. The aim in this document is to lay out many of the capabilities within grViz, which can be rearranged and repurposed for real-life situation. The shapes in the diagram are known as nodes and the connecting lines are called edges. There are also grouped edges which connect several nodes to the next node.

Very detailed information can be found on the GraphViz documentation webpage on how to add diverse types of attributes including types of nodes (variety of shapes), node/edge colors, and much more.

The code in the block below can be copied and pasted into a new .R script and repurposed.

DiagrammeR::grViz("               # All instructions are within a large character string
digraph surveillance_diagram {    # 'digraph' means 'directional graph', then the graph name 
  
  # graph statement
  #################
  graph [layout = dot,
         rankdir = TB,            # layout top-to-bottom
         fontsize = 24]
  

  # nodes (circles)
  #################
  
  #default seetings for the shapes and the 
  node [shape = circle,           
       fixedsize = true
       width = 1.3, 
       color = lavender, #default color of shape
       style = filled]                 
  
  #labels for nodes and alterations to the default shape, color, text font 
  1   [label = 'Twinkle', fontsize = 24] 
  2   [label = 'Twinkle', fillcolor = beige, shape = Rectangle] 
  3   [label = 'Star', fillcolor = red, shape = square, fontsize = 24] 
  4   [label = 'How I\nWonder', fontcolor = darkgreen, fillcolor = darkolivegreen1, shape = diamond] 
  5   [label = 'What you are!', fillcolor = aquamarine]
  6   [label = 'Up above', shape = octagon, fillcolor = coral]
  7   [label = 'The world', shape = oval, fillcolor = cornflowerblue]
  8   [label = 'so high', shape = star, fillcolor = darksalmon]
  9   [label = 'Like A\nDiamond', fillcolor = cadetblue, shape = diamond]
  10  [label = 'in the\nsky', fillcolor = aliceblue, fontsize = 24]
  11  [label = 'Twinkle\nTwinkle\nLittle star', fillcolor = white]
  
  # edges = labels for the connecting lines + alterations to default characteristics of line types (color/style)
  #######
  1 -> 3 [label = 'Little', fontcolor = black, color = red]
  2 -> 3 [label = '',fontcolor = black, color = red]
  3 -> 4 [label = '', fontcolor = darkgreen,color = darkgreen,style = dashed]
  4 -> 5 
  6 -> 7 
  6 -> 8 
  8 -> 9
  9 -> 10

  # grouped edge
  {1 2 3 4 5} -> 6 [style = dashed]
  { 7 8 9 10} -> 11 [style = dashed]
}
")