首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在DiagrammeR中将超链接插入到节点标签中

在DiagrammeR中将超链接插入到节点标签中
EN

Stack Overflow用户
提问于 2018-02-15 00:52:06
回答 1查看 665关注 0票数 3

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

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

美人鱼

使用DiagrammeR(diagram = "", type = "mermaid")可以在节点标签中使用超文本标记语言:

代码语言:javascript
复制
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")

但是要使用<a>标记,我们需要使用解析器忽略的=

代码语言:javascript
复制
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")

grViz

下面是与上面相同的流程图,只是去掉了所有的html并将其转换为grViz

代码语言:javascript
复制
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标记:

代码语言:javascript
复制
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']
      }
      ")

create_graph

DiagrammeR还可以让我们创建如下图:

代码语言:javascript
复制
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标记:

代码语言:javascript
复制
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()

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-25 01:22:19

我为美人鱼函数解决了这个问题:

代码语言:javascript
复制
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>选项需要双引号,值得庆幸的是,R接受对整个美人鱼代码块使用单引号。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48792355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档