简体   繁体   中英

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()

在此处输入图片说明

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?

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!

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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM