8

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?

Joachim Schork
  • 2,025
  • 3
  • 25
  • 48

2 Answers2

2

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!

Afsanefda
  • 3,069
  • 6
  • 36
  • 76
  • 1
    Thank you for your comment. If I use `fixedsize = FALSE` the node in the middle gets larger, but the size of the text remains the same. I want to keep the node size as it is and reduce only the text size of lines 2 and 3 (i.e. "These letters should be smaller"). – Joachim Schork Oct 01 '19 at 05:35
0

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"))
  • Thanks for your comment. If I run your code the font size remains the same. Is the code working for you? – Joachim Schork Sep 18 '18 at 08:30
  • Oh, i just found out `style` is for usually given the value filled if you'd like to fill a node with a color. So not useful. How about if you just the fontsize? It doesn't seem like DiagrammeR has a way to set the label fit inside a node automatically. :( –  Sep 18 '18 at 22:06
  • I am able to adjust the font size of the whole node. Unfortunately, I am not able to adjust only some words of a node. – Joachim Schork Sep 19 '18 at 07:57