1

I want to create a flowchart with the R package DiagrammeR. The text of some of the nodes should have a line break.

Consider the following reproducible example in R:

library("DiagrammeR")

# Create a node data frame (ndf)
ndf <- create_node_df(n = 4,
                      label = c("hi stacko", "aaa", "bbb", "ccc"))

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

# 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 %>%
  render_graph()

enter image description here

In this flowchart, I would like to add a line break between "hi" and "stacko" in the lower left node. I found some sources that suggested <br> or \n. Unfortunately, both did not work.

Question: How could I insert a line break in DiagrammeR?

4

1 回答 1

3

这对我有用:

ndf <- create_node_df(n = 4,label = c("hi\nstacko", "aaa", "bbb", "ccc"))

并且,当与其余代码一起运行时,会生成下图:

在此处输入图像描述

于 2018-02-01T19:41:11.943 回答