r - DiagrammeR - 箭头问题
问题描述
我正在尝试使用这个优秀的教程创建一个流程图:https ://dannyjnwong.github.io/STROBE-CONSORT-Diagrams-in-R/
library(DiagrammeR)
library(DiagrammeRsvg) #Needed if you want to export the image
library(rsvg) #Needed if you want to export the image
#Set the values which will go into each label.
a1 <- 'Total available patients\n(n = x)'
b1 <- ''
c1 <- ''
d1 <- 'Included for analysis\n(n = x - y - z)'
e1 <- 'Data linked with\nexternal dataset'
a2 <- ''
b2 <- 'Excluded because of\nexclusion criteria (n = y)'
c2 <- 'Excluded because of\nmissing values (n = z)'
d2 <- ''
e2 <- ''
#Create a node dataframe
ndf <- create_node_df(
n = 10,
label = c(a1, b1, c1, d1, e1, #Column 1
a2, b2, c2, d2, e2), #Column 2
style = c('solid', 'invis', 'invis', 'solid', 'solid', #Column 1
'invis', 'solid', 'solid', 'invis', 'invis'), #Column 2
shape = c('box', 'point', 'point', 'box', 'box', #Column 1
'plaintext', 'box', 'box', 'point', 'point'), #Column 2
width = c(3, 0.001, 0.001, 3, 3, #Column 1
2, 2.5, 2.5, 0.001, 0.001), #Column 2
height = c(1, 0.001, 0.001, 1, 1, #Column 1
1, 1, 1, 0.001, 0.001), #Column 2
fontsize = c(rep(14, 10)),
fontname = c(rep('Helvetica', 10)),
penwidth = 1.5,
fixedsize = 'true')
#Create an edge dataframe
edf <- create_edge_df(
from = c(1, 2, 3, 4, #Column 1
6, 7, 8, 9, #Column 2
2, 3 #Horizontals
),
to = c(2, 3, 4, 5, #Column 1
7, 8, 9, 10, #Column 2
7, 8 #Horizontals
),
arrowhead = c('none', 'none', 'normal', 'normal', #Column 1
'none', 'none', 'none', 'none', #Column 2
'normal', 'normal' #Horizontals
),
color = c('black', 'black', 'black', 'black', #Column 1
'#00000000', '#00000000', '#00000000', '#00000000', #Column 2
'black', 'black' #Horizontals
),
constraint = c(rep('true', 8), #Columns
rep('false', 2) #Horizontals
)
)
g <- create_graph(ndf,
edf,
attr_theme = NULL)
render_graph(g)
但是,当我在计算机上运行代码时,它看起来像这样
有热心帮忙的吗?
最好的问候,H
解决方案
也许有点晚了,但总比没有好。您必须使用width = 0
和创建两个节点height = 0
,箭头可以从这些节点水平起源。它们需要被定义为子图才能位于水平轴上。
DiagrammeR::grViz("digraph prisma{
node [shape=box, fontsize = 12, fontname = 'Helvetica', width = 2];
a; b; c; d; e
# create 2 nodes without box around
node [shape = point, width = 0, height = 0]
x1; x2
graph [splines=ortho, nodesep=1, dpi = 72]
# Labels
a [label = 'Total available patients\n(n = x)'];
b [label = 'Excluded because of\nexclusion criteria (n = y)'];
c [label = 'Excluded because of\nmissing values (n = z)'];
d [label = 'Included for analysis\n(n = x - y - z)']
e [label = 'Data linked with\nexternal dataset']
# Edge definitions
a -> x1 [arrowhead='none']
x1 -> x2 [arrowhead='none']
x1 -> b
x2 -> c
x2 -> d
d -> e
# Make subgraph definition so arrow is horzontal
subgraph {
rank = same; b; x1;
}
subgraph {
rank = same; c; x2;
}
}
}
")
由reprex 包于 2021-08-06 创建(v2.0.1)
会话信息sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.3 (2020-10-10)
#> os macOS Catalina 10.15.7
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate de_CH.UTF-8
#> ctype de_CH.UTF-8
#> tz Europe/Zurich
#> date 2021-08-06
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.2)
#> callr 3.7.0 2021-04-20 [1] CRAN (R 4.0.2)
#> cli 3.0.0 2021-06-30 [1] CRAN (R 4.0.2)
#> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.2)
#> curl 4.3.2 2021-06-23 [1] CRAN (R 4.0.2)
#> DiagrammeR 1.0.6.1 2020-05-08 [1] CRAN (R 4.0.2)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
#> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.0.2)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.0.2)
#> htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.0.2)
#> htmlwidgets 1.5.2 2020-10-03 [1] CRAN (R 4.0.2)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.0.2)
#> jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.0.2)
#> knitr 1.33 2021-04-24 [1] CRAN (R 4.0.2)
#> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.2)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2)
#> mime 0.11 2021-06-23 [1] CRAN (R 4.0.2)
#> pillar 1.6.1 2021-05-16 [1] CRAN (R 4.0.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
#> processx 3.5.2 2021-04-30 [1] CRAN (R 4.0.2)
#> ps 1.6.0 2021-02-28 [1] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.0)
#> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2)
#> RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.0)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.0.3)
#> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.0.2)
#> rmarkdown 2.9 2021-06-15 [1] CRAN (R 4.0.2)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.0.2)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0)
#> stringi 1.7.3 2021-07-16 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> styler 1.3.2 2020-02-23 [1] CRAN (R 4.0.2)
#> tibble 3.1.2 2021-05-16 [1] CRAN (R 4.0.2)
#> utf8 1.2.1 2021-03-12 [1] CRAN (R 4.0.2)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.0.2)
#> visNetwork 2.0.9 2019-12-06 [1] CRAN (R 4.0.2)
#> webshot 0.5.2 2019-11-22 [1] CRAN (R 4.0.0)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.0.2)
#> xfun 0.24 2021-06-15 [1] CRAN (R 4.0.2)
#> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.0)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
推荐阅读
- node.js - 从反应原生应用程序请求 POST 返回未定义的响应
- .net - 是否可以在 .NET 代码中找到所有具体类型的泛型方法调用?
- ansible - Ansible Script 模块如何返回脚本中每个命令的执行结果?
- c++ - 检查 std::any 变量是否包含 std::string 时出现问题
- karate - 如何根据响应进行有条件的空手道中止
- javascript - 在 await 完成执行之前函数返回
- sql - 从R中保存在.sql文件中的sql数据库导入数据
- wpf - 如何在 WPF 中按字节 [] 更新 WritableBitmap
- amazon-web-services - 如何删除或更新 AWS 安全组中的特定规则?
- networking - 无法创建网络实例来与外界通信。无法建立新连接:[Errno 111] Connection refused',))