You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R的DiagrammeR包流程图节点内调整部分文本字体大小

Resizing Partial Text in DiagrammeR Flowchart Nodes

Got it, you want to shrink part of the text inside a specific node in your DiagrammeR flowchart—here's a straightforward solution using Graphviz's HTML label support, which lets you fine-tune text sizing within a single node.

Modified Code with Partial Text Resizing

library("DiagrammeR")

# Create node data frame (ndf) with HTML-formatted labels for partial text sizing
ndf <- create_node_df(
  n = 4,
  label = c(
    "aaa", 
    "bbb", 
    "<span style='font-size:14px;'>Same size</span><br/><span style='font-size:10px;'>These letters<br/>should be smaller</span>", 
    "ccc"
  ),
  shape = "rectangle",  # Critical: Shapes like rectangle support HTML rendering
  style = "filled",
  fillcolor = "#f0f8ff"
)

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

# Build and render the graph
graph <- create_graph(
  nodes_df = ndf,
  edges_df = edf
)

# View the final flowchart
render_graph(graph)

Key Details to Note:

  • HTML Label Formatting: We replace raw text with HTML elements to control text size. Use <span style='font-size:XXpx;'> to set precise pixel sizes for different text segments.
  • Line Breaks: Use <br/> instead of \n for line breaks in HTML-formatted labels.
  • Node Shape: Ensure your node uses a shape that supports HTML rendering (e.g., rectangle, roundedrect—avoid plaintext or ellipse if you need HTML styling).
  • Alternative: Simplified Font Tags: If you prefer simpler syntax, you can use the <font size="2"> tag (size values range 1-7, default is 3) instead of CSS styling:
    "<font size='3'>Same size</font><br/><font size='2'>These letters<br/>should be smaller</font>"
    

If you wanted to resize an entire node's text (not just part of it), you could add a fontsize column to your node data frame, but for partial text control, HTML formatting is the most flexible approach.

内容的提问来源于stack exchange,提问作者Joachim Schork

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:37:57