I would like to create a flowchart with the DiagrammeR
package in R
. The graphic should look as in the following example, but I would like to add some labels above the arrows.
Consider the following reproducible example in 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")
With this code, I can create the following graph:
Above the 4 arrows of the graph I would like to add the labels a, b, c and d. Unfortunately, I wasn't able to find anything about that in the documentation. It seems like I am doing something wrong with the rel
argument in within the function create_edge_df
.
I think you add label = my_vector_of_labels
into the definition of 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"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With