5

我想DiagrammeRR. 图形应如下例所示,但我想在箭头上方添加一些标签。

考虑以下可重现的示例R

library("DiagrammeR")

# Create a node data frame (ndf)
ndf <- create_node_df(n = 4,
                      shape = c("rectangle"))

# Create an edge data frame (edf)
edf <- create_edge_df(from = c(1, 2, 3, 3),
                      to = c(4, 3, 1, 4),
                      rel = c("a", "b", "c", "d"))

# Create a graph with the ndf and edf
graph <- create_graph(nodes_df = ndf,
                      edges_df = edf)

# Create a PDF file for the graph (`graph.pdf`)
graph %>%
  export_graph(file_name = "graph.pdf",
               title = "Simple Graph")

使用此代码,我可以创建以下图表:

在此处输入图像描述

在图表的 4 个箭头上方,我想添加标签 a、b、c 和 d。不幸的是,我无法在文档中找到任何相关信息。rel好像我在函数中的参数做错了什么create_edge_df

4

1 回答 1

4

我认为您添加label = my_vector_of_labels到 create_edges 的定义中:

# Create an edge data frame (edf) using diagrammer v 0.9.2
edf <- create_edge_df(from = c(1, 2, 3, 3),
                  to = c(4, 3, 1, 4),
                  rel = c("a", "b", "c", "d"),
                  label = c("a", "b", "c", "d"))
于 2018-01-30T13:50:48.403 回答