0

I am trying to make a flow to show my experimental design. I have something that works, but I would like to add another layer at the bottom-which adds a question box to each group, which should be big enough to read. An example of what I have is image 1 hoping for is in image 2. Such that group 1 has a question and answer (with arrows) and group 2 and 3 has a question and 3 answers (with arrows). Of course, the arrows should be black and in the right place-its just hard to do in word!

Does anyone know how I can do this?

Image 1 image 1

Image 2 image 2 Code:

# install.packages("DiagrammeR")
#library(DiagrammeR)

schematic <- grViz("digraph lexicon {
      # node definitions with substituted label text
node [fontname = Helvetica, shape = rectangle, style=filled,color=lightgrey]
      tab1 [label = '@@1']
      tab2 [label = '@@2']
      tab3 [label = '@@3']
      tab4 [label = '@@4']
      tab5 [label = '@@5']
      node [shape = rectangle, fillcolor=PeachPuff]
      tab6 [label = '@@6']
      node [shape = rectangle, fillcolor=CadetBlue]
      tab7 [label = '@@7']
      node [shape = rectangle, fillcolor=Lavender]
      tab8 [label = '@@8']

node [fontname = Helvetica, shape = rectangle, style=bold]
      m1 [label = 'Did not agree to participate n=18']
      m2 [label = 'Under 18 years n=11']
      m3 [label = 'No smoke in past 3 months n=8']
      m4 [label = 'Did not complete survey n=155']
      # creating horizontal lines
      node [shape=none, width=0, height=0, label='']
      {rank=same; tab1 -> m1}
      {rank=same; tab2 -> m2}
      {rank=same; tab3 -> m3}
      {rank=same; tab4 -> m4}
      # edge definitions with the node IDs
     tab1 -> tab2 -> tab3 -> tab4 -> tab5->{tab6 tab7 tab8};
      }
      [1]: 'Raw Data n=434'
      [2]: 'Agreed to participate n=406'
      [3]: 'Over 18 years n=491'
      [4]: 'smoke in past 3 months=403'
      [5]: 'Final sample n=238'
      [6]: 'Group1 n=82'
      [7]: 'Group2 n=98'
      [8]: 'Group3 n=88'
      ")

jpeg(file = "schematic.jpg")
schematic
Gabriella
  • 421
  • 3
  • 11

1 Answers1

0

You can just add some more nodes

schematic <- grViz("digraph lexicon {
          # node definitions with substituted label text
    node [fontname = Helvetica, shape = rectangle, style=filled,color=lightgrey]
          tab1 [label = '@@1']
          tab2 [label = '@@2']
          tab3 [label = '@@3']
          tab4 [label = '@@4']
          tab5 [label = '@@5']
          node [shape = rectangle, fillcolor=PeachPuff]
          tab6 [label = '@@6']
          node [shape = rectangle, fillcolor=CadetBlue]
          tab7 [label = '@@7']
          node [shape = rectangle, fillcolor=Lavender]
          tab8 [label = '@@8']
    
    node [fontname = Helvetica, shape = rectangle, style=bold]
          m1 [label = 'Did not agree to participate n=18']
          m2 [label = 'Under 18 years n=11']
          m3 [label = 'No smoke in past 3 months n=8']
          m4 [label = 'Did not complete survey n=155']
    
# ------> NEW NODES      
    node [fontname = Helvetica, shape = rectangle, style=bold,  width = 2.5, height = 1, ALIGN = LEFT]
          q1 [label = 'Question 1 \\l\n\n']
          q2 [label = 'Question 2 \\l\n\n']
          q3 [label = 'Question 3 \\l\n\n']
          a11 [label = 'Answer 1 \\l\n\n']
          a21 [label = 'Answer 1 \\l\n\n']
          a22 [label = 'Answer 2 \\l\n\n']
          a23 [label = 'Answer 3 \\l\n\n']
          a31 [label = 'Answer 1 \\l\n\n']
          a32 [label = 'Answer 2 \\l\n\n']
          a33 [label = 'Answer 3 \\l\n\n']
          
          
    
    # creating horizontal lines
          node [shape=none, width=0, height=0, label='']
          {rank=same; tab1 -> m1}
          {rank=same; tab2 -> m2}
          {rank=same; tab3 -> m3}
          {rank=same; tab4 -> m4}
    # edge definitions with the node IDs
         tab1 -> tab2 -> tab3 -> tab4 -> tab5->{tab6 tab7 tab8};
#--------> ATTACH NEW NODES
         tab6 -> q1 -> a11
         tab7 -> q2 -> a21 -> a22 -> a23
         tab8 -> q3 -> a31 -> a32 -> a33
          }
          [1]: 'Raw Data n=434'
          [2]: 'Agreed to participate n=406'
          [3]: 'Over 18 years n=491'
          [4]: 'smoke in past 3 months=403'
          [5]: 'Final sample n=238'
          [6]: 'Group1 n=82'
          [7]: 'Group2 n=98'
          [8]: 'Group3 n=88'
          ")
    
    jpeg(file = "schematic.jpg")
    schematic
drT
  • 123
  • 3
  • 3
  • 10