Joachim Schork
Joachim Schork

Reputation: 2147

DiagrammeR: Adjust font size within node

I want to create a flowchart with the DiagrammeR Package in R. Within some nodes, I want to reduce the font size of some parts of the text.

Consider the following example in R:

library("DiagrammeR")

# Create a node data frame (ndf)
ndf <- create_node_df(n = 4,label = c("aaa", "bbb",
                                      "Same size\nThese letters\nshould be smaller",
                                      "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)

# Print graph
graph %>%
  render_graph()

enter image description here

The font size of the node in the middle should partly be reduced. The text "Same size" should be kept as it is. The font size of the text "These letters should be smaller" should be reduced.

Question: How could I adjust the font size for some parts of the text within a node?

Upvotes: 8

Views: 2456

Answers (2)

James O&#39;Neil
James O&#39;Neil

Reputation: 21

Try fixedsize = FALSE.

This adjusts the node to stretch to fit the words. It's documented here under Create_nodes but they really do not explain it very well.

The behavior to me was Fixedsize=True (in that no matter what we put in it.. the size was fixed).

So I've tried fixedsize = FALSE and it worked!

Upvotes: 2

user9307178
user9307178

Reputation:

Were you able to make it work?

It looks like you can add style="filled"; reference: https://www.rdocumentation.org/packages/DiagrammeR/versions/1.0.0/topics/create_node_df

ndf <- create_node_df(n = 4, style="filled", label = c("aaa", "bbb",
                                      "Same size\nThese letters\nshould be smaller",
                                      "ccc"))

Upvotes: 0

Related Questions