Joachim Schork
Joachim Schork

Reputation: 2147

DiagrammeR: How to insert a line break within a node?

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?

Upvotes: 2

Views: 2025

Answers (1)

Constantinos
Constantinos

Reputation: 1327

This works for me:

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

and, when run with the remainder of the code, produces the following diagram:

enter image description here

Upvotes: 3

Related Questions