gpt4 book ai didi

r - 在 DiagrammeR 中将超链接插入节点标签

转载 作者:行者123 更新时间:2023-12-04 16:05:53 24 4
gpt4 key购买 nike

我希望能够使用 DiagrammeR 创建流程图在 R 中,以便我可以通过 devtools::install_github('rich-iannone/DiagrammeRsvg') 导出 SVG包裹。

我的流程图必须在某些节点中包含超链接,不幸的是我找不到一种可接受的方法来创建具有功能的节点标签 <a>标签。以下是我尝试过的不同方法:

美人鱼

使用 DiagrammeR(diagram = "", type = "mermaid")可以在节点标签中使用 HTML 标签:

library("DiagrammeR")
DiagrammeR("graph TB;
A{Is your data public?} -- yes -->C;
A -- no -->B[<center><b>Oxshef: dataviz</b> only supports researchers <br> in the creation of interactive data visualisations that public</center>];
C{<center>Please make it public?</center>};
D[<center>Supported!</center>];
E[<center>Unsupported!</center>];
F[Refer to our tutorial];
C -- yes -->D;
C -- no -->E;
C -- I don't know -->F")

enter image description here

但是要使用 <a>我们需要使用 = 的标签解析器吐出来的:
DiagrammeR("graph TB;
A{Is your data public?} -- yes -->C;
A -- no -->B[<center><b>Oxshef: dataviz</b> only supports researchers <br> in the creation of interactive data visualisations that public</center>];
C{<center>Please make it public?</center>};
D[<center>Supported!</center>];
E[<center>Unsupported!</center>];
F[Refer to our <a href='http://google.com'>tutorial</a>];
C -- yes -->D;
C -- no -->E;
C -- I don't know -->F")

enter image description here

可视化

这是与上面相同的流程图,但所有 html 都被删除并转换为 grViz :
grViz("
digraph boxes_and_circles {

# a 'graph' statement
graph [overlap = true, fontsize = 10]

# several 'node' statements
node [shape = box,
fontname = Helvetica]
A [label = 'Is your data public?']; B [label = 'Please make it public'];
C [label = 'Tech Question']; D [label = 'Supported' ];
E [label = 'Unsupported!']; F [label = 'Refer to our tutorial']

# several 'edge' statements
A->B A->C C->D [label = 'yes'] C->E [label = 'no'] C->F [label = 'Unknown']
}
")

这不支持 HTML 标签:
grViz("
digraph boxes_and_circles {

# a 'graph' statement
graph [overlap = true, fontsize = 10]

# several 'node' statements
node [shape = box,
fontname = Helvetica]
A [label = 'Is your data public?']; B [label = '<b>Please</b> make it public'];
C [label = 'Tech Question']; D [label = 'Supported' ];
E [label = 'Unsupported!']; F [label = 'Refer to our tutorial']

# several 'edge' statements
A->B A->C C->D [label = 'yes'] C->E [label = 'no'] C->F [label = 'Unknown']
}
")

enter image description here

创建图
DiagrammeR还让我们创建图形如下:
ndf_no_tags <- create_node_df(n = 6,
label = c("Is your data public?",
"Please make it public",
"Tech Question",
"Supported",
"Unsupported",
"Refer to our tutorial"))
# Create an edge data frame (edf)
edf <- create_edge_df(from = c(1, 1, 3, 3, 3),
to = c(2, 3, 4, 5, 6))
ndf_no_tags %>%
create_graph(edges_df = edf) %>%
render_graph()

但它转义了 HTML 标签:
ndf_with_tags <- create_node_df(n = 6,
label = c("Is your data public?",
"<b>Please</b> make it public",
"Tech Question",
"Supported",
"Unsupported",
"Refer to our tutorial"))
ndf_with_tags %>%
create_graph(edges_df = edf) %>%
render_graph()

enter image description here

最佳答案

我想出了美人鱼功能:

mermaid('
graph LR
A-->B
A-->C
C-->E
B-->D
C-->D
D-->F
E-->F
click B "http://www.github.com" "This is a link"
')
click B <link> option 需要双引号,幸运的是 R 接受整个美人鱼代码块的单引号。

关于r - 在 DiagrammeR 中将超链接插入节点标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48792355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com