Data for Flow Diagram

use "data\NHANES0518_new.dta", clear

ta MEC_response
ta BP_miss MEC_response

ta MJ_miss BP_miss if MEC_response==1

ta AGE_exclude if BP_miss==0 & MJ_miss==0

ta AGE_exclude
ta AGE_exclude BP_miss
ta BP_miss MJ_miss if AGE_exclude==0


ta BP_miss MJ_miss if AGE_exclude==0 & gndr==0
ta BP_miss MJ_miss if AGE_exclude==0 & gndr==1

ta gndr if include==1
   MEC Response |      Freq.     Percent        Cum.
----------------+-----------------------------------
Did not respond |      2,826        4.03        4.03
      Responded |     67,364       95.97      100.00
----------------+-----------------------------------
          Total |     70,190      100.00

      Meets BP |
     Inclusion |     MEC Response
      Criteria | Did not r  Responded |     Total
---------------+----------------------+----------
Not Missing BP |         0     48,783 |    48,783 
    Missing BP |     2,826     18,581 |    21,407 
---------------+----------------------+----------
         Total |     2,826     67,364 |    70,190 

      Meets MJ |  Meets BP Inclusion
     Inclusion |       Criteria
      Criteria | Not Missi  Missing B |     Total
---------------+----------------------+----------
Not Missing MJ |    22,321      1,239 |    23,560 
    Missing MJ |    26,462     17,342 |    43,804 
---------------+----------------------+----------
         Total |    48,783     18,581 |    67,364 


   Meets Age |
   Inclusion |
    Criteria |      Freq.     Percent        Cum.
-------------+-----------------------------------
   Age 20-59 |     21,020       94.17       94.17
Age Excluded |      1,301        5.83      100.00
-------------+-----------------------------------
       Total |     22,321      100.00


   Meets Age |
   Inclusion |
    Criteria |      Freq.     Percent        Cum.
-------------+-----------------------------------
   Age 20-59 |     26,269       37.43       37.43
Age Excluded |     43,921       62.57      100.00
-------------+-----------------------------------
       Total |     70,190      100.00


   Meets Age |  Meets BP Inclusion
   Inclusion |       Criteria
    Criteria | Not Missi  Missing B |     Total
-------------+----------------------+----------
   Age 20-59 |    23,411      2,858 |    26,269 
Age Excluded |    25,372     18,549 |    43,921 
-------------+----------------------+----------
       Total |    48,783     21,407 |    70,190 

      Meets BP |  Meets MJ Inclusion
     Inclusion |       Criteria
      Criteria | Not Missi  Missing M |     Total
---------------+----------------------+----------
Not Missing BP |    21,020      2,391 |    23,411 
    Missing BP |     1,188      1,670 |     2,858 
---------------+----------------------+----------
         Total |    22,208      4,061 |    26,269 

      Meets BP |  Meets MJ Inclusion
     Inclusion |       Criteria
      Criteria | Not Missi  Missing M |     Total
---------------+----------------------+----------
Not Missing BP |    10,679      1,424 |    12,103 
    Missing BP |       703        859 |     1,562 
---------------+----------------------+----------
         Total |    11,382      2,283 |    13,665 

      Meets BP |  Meets MJ Inclusion
     Inclusion |       Criteria
      Criteria | Not Missi  Missing M |     Total
---------------+----------------------+----------
Not Missing BP |    10,341        967 |    11,308 
    Missing BP |       485        811 |     1,296 
---------------+----------------------+----------
         Total |    10,826      1,778 |    12,604 

     Gender |      Freq.     Percent        Cum.
------------+-----------------------------------
     Female |     10,679       50.80       50.80
       Male |     10,341       49.20      100.00
------------+-----------------------------------
      Total |     21,020      100.00

New Flow Diagram

# Define some sample data
data <- list(a=70190 , b=48783, c=22321, d=21020, e=10679, f=10341)

DiagrammeR::grViz("
digraph rmarkdown{

# Box
node [shape = box]

A;

A[label = 
    <
    Missing BP data:<br ALIGN = 'LEFT'/> 
    &#8226; No mobile examination<br ALIGN = 'LEFT'/> 
    center exam (n = 2826)<br ALIGN = 'LEFT'/> 
    &#8226; Less than 3 BP<br ALIGN = 'LEFT'/>
    readings (n = 18581)<br ALIGN = 'LEFT'/>
    >
]

B;

B[label = 
    <
    Missing cannabis data<br ALIGN = 'LEFT'/> 
    (n = 26462)<br ALIGN = 'LEFT'/>
    >
]

C;

C[label = 
    <
    Not in age range 20-59 years<br ALIGN = 'LEFT'/> 
    (n = 1301)<br ALIGN = 'LEFT'/>
    >
]

a [label = '@@1']
a1 [shape = point width = 0.01]
b [label = '@@2']
b1 [shape = point width = 0.01]
c [label = '@@3']
c1 [shape = point width = 0.01]
d [label = '@@4']
e [label = '@@5']
f [label = '@@6']


a -> a1 [arrowhead = none]
a1 -> A
a1 -> b 
b -> b1 [arrowhead = none]
b1 -> B
b1 -> c
c -> c1 [arrowhead = none]
c1 -> C
c1 -> d -> e
d -> f

{rank=same; a1 A}
{rank=same; b1 B}
{rank=same; c1 C}

}

[1]: paste0('NHANES 2005-2018 (n = ', data$a, ')')
[2]: paste0('Not missing BP data (n = ', data$b, ')')
[3]: paste0('Not missing exposure and outcome data (n = ', data$c, ')')
[4]: paste0('Adults age 20-59 with BP data & cannabis use data (n = ', data$d, ')')
[5]: paste0('Women (n = ', data$e, ')')
[6]: paste0('Men (n = ', data$f, ')')
")

Old 2007-2018 Flow Diagram

# Define some sample data
data <- list(a=59842 , b=42674, c=19811, d=18510, e=9353, f=9157)

DiagrammeR::grViz("
digraph rmarkdown{

# Box
node [shape = box]

A;

A[label = 
    <
    Missing BP data:<br ALIGN = 'LEFT'/> 
    &#8226; No mobile examination center exam<br ALIGN = 'LEFT'/> 
    (n = 2428)<br ALIGN = 'LEFT'/> 
    &#8226; Insufficient BP data for AHA/ACC<br ALIGN = 'LEFT'/>
    classification (n = 14740)<br ALIGN = 'LEFT'/>
    >
]

B;

B[label = 
    <
    Missing cannabis use data<br ALIGN = 'LEFT'/> 
    (n = 22863)<br ALIGN = 'LEFT'/>
    >
]

C;

C[label = 
    <
    Outside of age range 20-69 years<br ALIGN = 'LEFT'/> 
    (n = 1301)<br ALIGN = 'LEFT'/>
    >
]

a [label = '@@1']
a1 [shape = point width = 0.01]
b [label = '@@2']
b1 [shape = point width = 0.01]
c [label = '@@3']
c1 [shape = point width = 0.01]
d [label = '@@4']
e [label = '@@5']
f [label = '@@6']


a -> a1 [arrowhead = none]
a1 -> A
a1 -> b 
b -> b1 [arrowhead = none]
b1 -> B
b1 -> c
c -> c1 [arrowhead = none]
c1 -> C
c1 -> d -> e
d -> f

{rank=same; a1 A}
{rank=same; b1 B}
{rank=same; c1 C}

}

[1]: paste0('NHANES 2007-2018 (n = ', data$a, ')')
[2]: paste0('Sufficient BP data (n = ', data$b, ')')
[3]: paste0('Sufficient exposure and outcome data (n = ', data$c, ')')
[4]: paste0('Adults age 20-69 with BP data & cannabis use data (n = ', data$d, ')')
[5]: paste0('Women (n = ', data$e, ')')
[6]: paste0('Men (n = ', data$f, ')')
")

Old Flow Diagram

# Define some sample data
data <- list(a=59842 , b=28721, c=26046, d=18510, e=9353, f=9157)

DiagrammeR::grViz("
digraph graph2 {

graph [layout = dot]

# node definitions with substituted label text
node [shape = rectangle, width = 4, fillcolor = Biege]
a [label = '@@1']
a1 [shape = point width = 0.01]
a2 [label = 'Missing BP data\nNo mobile examination center exam\nInsufficient BP data for AHA/ACC clasification' align = right]
b [label = '@@2']
c [label = '@@3']
d [label = '@@4']
e [label = '@@5']
f [label = '@@6']

a -> a1 [arrowhead = none]
a1 -> b -> c -> d -> e
a1 -> a2
d -> f

{rank=same; a1 a2}

}

[1]: paste0('NHANES 2007-2018 (n = ', data$a, ')')
[2]: paste0('Adults age 20-69 (n = ', data$b, ')')
[3]: paste0('Adults age 20-69 with BP data (n = ', data$c, ')')
[4]: paste0('Adults age 20-69 with BP data & cannabis use data (n = ', data$d, ')')
[5]: paste0('Women (n = ', data$e, ')')
[6]: paste0('Men (n = ', data$f, ')')
")