admin管理员组文章数量:1289391
I am new to R and trying replicate work from research I come across.
I am looking to replicate this flowchart:
This is the code I have so far:
library(DiagrammeR)
grViz(" digraph sample_selection { graph [layout = dot, rankdir = TB, splines = ortho, overlap = true]
node [shape = box, style = filled, fillcolor = white]
# Nodes for each year '2010 Survey\\nParticipants\\n(n = 32,846)' [group = years] '2011 Survey\\nParticipants\\n(n = 35,313)' [group = years] '2012 Survey\\nParticipants\\n(n = 38,974)' [group = years] '2013 Survey\\nParticipants\\n(n = 36,940)' [group = years]
# Combined node '2010-2013\\n(n = 144,073)'
# Exclusion nodes 'Excluded participants\\n<18 years at time of\\nsurvey\\n(n = 41,277)' 'Excluded participants\\nwithout medical visit\\nin the last 12 months\\n(45,843)' [style = 'filled,rounded', penwidth = 2, fillcolor = white, color = black] 'Excluded participants\\nwithout a usual\\nsource of care\\n(n = 8,984)'
# Final sample node 'Final Sample\\npopulation (n = 47,969)\\nrepresenting 130\\nmillion individuals'
# Intermediate node 'n = 102,796' 'n = 56,953'
# Edges {rank = same; '2010 Survey\\nParticipants\\n(n = 32,846)'; '2011 Survey\\nParticipants\\n(n = 35,313)'; '2012 Survey\\nParticipants\\n(n = 38,974)'; '2013 Survey\\nParticipants\\n(n = 36,940)'} {rank = same; '2010-2013\\n(n
= 144,073)'} '2010 Survey\\nParticipants\\n(n = 32,846)' -> '2010-2013\\n(n = 144,073)' '2011 Survey\\nParticipants\\n(n = 35,313)' -> '2010-2013\\n(n = 144,073)' '2012 Survey\\nParticipants\\n(n = 38,974)' -> '2010-2013\\n(n = 144,073)' '2013 Survey\\nParticipants\\n(n = 36,940)' -> '2010-2013\\n(n = 144,073)'
'2010-2013\\n(n = 144,073)' -> 'Excluded participants\\n<18 years at time of\\nsurvey\\n(n = 41,277)' '2010-2013\\n(n = 144,073)' -> 'n = 102,796'
'n = 102,796' -> 'Excluded participants\\nwithout medical visit\\nin the last 12 months\\n(45,843)' 'n = 102,796' -> 'n = 56,953'
'n = 56,953' -> 'Excluded participants\\nwithout a usual\\nsource of care\\n(n = 8,984)' 'n = 56,953' -> 'Final Sample\\npopulation (n = 47,969)\\nrepresenting 130\\nmillion individuals' } ")
Which produces this:
Guidance on how to get those lines merged together?
I am new to R and trying replicate work from research I come across.
I am looking to replicate this flowchart:
This is the code I have so far:
library(DiagrammeR)
grViz(" digraph sample_selection { graph [layout = dot, rankdir = TB, splines = ortho, overlap = true]
node [shape = box, style = filled, fillcolor = white]
# Nodes for each year '2010 Survey\\nParticipants\\n(n = 32,846)' [group = years] '2011 Survey\\nParticipants\\n(n = 35,313)' [group = years] '2012 Survey\\nParticipants\\n(n = 38,974)' [group = years] '2013 Survey\\nParticipants\\n(n = 36,940)' [group = years]
# Combined node '2010-2013\\n(n = 144,073)'
# Exclusion nodes 'Excluded participants\\n<18 years at time of\\nsurvey\\n(n = 41,277)' 'Excluded participants\\nwithout medical visit\\nin the last 12 months\\n(45,843)' [style = 'filled,rounded', penwidth = 2, fillcolor = white, color = black] 'Excluded participants\\nwithout a usual\\nsource of care\\n(n = 8,984)'
# Final sample node 'Final Sample\\npopulation (n = 47,969)\\nrepresenting 130\\nmillion individuals'
# Intermediate node 'n = 102,796' 'n = 56,953'
# Edges {rank = same; '2010 Survey\\nParticipants\\n(n = 32,846)'; '2011 Survey\\nParticipants\\n(n = 35,313)'; '2012 Survey\\nParticipants\\n(n = 38,974)'; '2013 Survey\\nParticipants\\n(n = 36,940)'} {rank = same; '2010-2013\\n(n
= 144,073)'} '2010 Survey\\nParticipants\\n(n = 32,846)' -> '2010-2013\\n(n = 144,073)' '2011 Survey\\nParticipants\\n(n = 35,313)' -> '2010-2013\\n(n = 144,073)' '2012 Survey\\nParticipants\\n(n = 38,974)' -> '2010-2013\\n(n = 144,073)' '2013 Survey\\nParticipants\\n(n = 36,940)' -> '2010-2013\\n(n = 144,073)'
'2010-2013\\n(n = 144,073)' -> 'Excluded participants\\n<18 years at time of\\nsurvey\\n(n = 41,277)' '2010-2013\\n(n = 144,073)' -> 'n = 102,796'
'n = 102,796' -> 'Excluded participants\\nwithout medical visit\\nin the last 12 months\\n(45,843)' 'n = 102,796' -> 'n = 56,953'
'n = 56,953' -> 'Excluded participants\\nwithout a usual\\nsource of care\\n(n = 8,984)' 'n = 56,953' -> 'Final Sample\\npopulation (n = 47,969)\\nrepresenting 130\\nmillion individuals' } ")
Which produces this:
Guidance on how to get those lines merged together?
Share Improve this question asked Feb 20 at 5:04 Ronald SanchezRonald Sanchez 731 silver badge8 bronze badges1 Answer
Reset to default 2Not a DiagrammR solution, but the flowchart package does this reasonably well.
library(flowchart)
fc1 <- as_fc(N=144073, label="2010-2013 Surveys", text_pattern = "{label}") |>
fc_split(N=c(32846, 35313, 38974, 36940),
label=c("2010 Survey", "2011 Survey", "2012 Survey", "2013 Survey"),
text_pattern = "{label}\n(n={n})")
fc2 <- as_fc(N=144073, text_pattern = "(n={n})") |>
fc_filter(N=102796,
text_pattern = "(n={n})",
show_exc = TRUE,
label_exc = "Excluded participants\n
<18 years at time\nof survey",
text_pattern_exc = "{label}\n(n={n})",
text_fs_exc = 8,
offset_exc=0.2) |>
fc_filter(N=56953,
text_pattern = "(n={n})",
show_exc = TRUE,
label_exc = "Excluded participants\n
without medical visit\n
in the last 12 months",
text_pattern_exc = "{label}\n(n={n})",
text_fs_exc = 8,
offset_exc=0.2) |>
fc_filter(N=47969,
label = "Final sample\n
population representing\n
130 million individuals",
text_pattern = "{label}\n(n={n})",
show_exc = TRUE,
label_exc = "Excluded participants\n
without a usual\n
source of care",
text_pattern_exc = "{label}\n(n={n})",
text_fs_exc = 8,
offset_exc=0.2)
list(fc1, fc2) |>
fc_stack(unite=TRUE) |>
fc_draw(arrow_angle=0)
本文标签: rDiagrammeR Merging lines in flowchartStack Overflow
版权声明:本文标题:r - DiagrammeR: Merging lines in flowchart - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741457875a2379860.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论