DiagrammeR流程图垂直节点对齐与箭头优化技术咨询
Fixing Layout and Arrow Issues in DiagrammeR Flowchart
Got it, let's tackle those flowchart problems one by one. I've revised your code to address all the layout alignment, straight arrow, and optional polyline arrow requests:
library(DiagrammeR) grViz("digraph flowchart { # Set global node defaults to avoid repetition node [fontname = Helvetica] # node type 1: starting and ending node node [shape = oval] start [label = '@@1'] pro2 [label = '@@6'] # node type 2: decision node [shape = diamond] dec1 [label = '@@2'] dec2 [label = '@@3'] dec3 [label = '@@4'] # node type 3: process node node [shape = rectangle] pro1 [label = '@@5'] pro3 [label = '@@7'] # Rank adjustments for vertical alignment {rank = same; start dec1 dec2 pro1} # Align START, decision1, decision2, process1 vertically {rank = same; pro3 dec3 pro2} # Align process3, decision3, END vertically # Edge definitions with fixes edge[tailclip = true, headclip = true]; # Basic flow start -> dec1 [dir=forward] dec1 -> dec2 [label = '', headport = 'n', tailport = 's'] # Straight vertical arrow dec1 -> pro3 [label = '', headport = 'n', tailport = 'e'] # Fix decision2 to process1: straight vertical arrow dec2 -> pro1 [label = '', tailport = 's', headport = 'n'] dec2 -> pro3 [label = ''] # Fix process3 to decision3: straight vertical arrow pro3 -> dec3 [label = '', tailport = 's', headport = 'n'] dec3 -> pro2 [label = '', tailport = 's', headport = 'n'] # Straight vertical arrow dec3 -> pro3 [label = '', headport = 'e', tailport = 'e'] # Optional: Polyline arrow from process1 to decision1 (horizontal then vertical then horizontal) # Add a hidden dummy node to create the polyline path node [shape=point, style=invisible] dummy1 [pos=""] {rank = same; pro1 dummy1} # Align dummy node with process1 horizontally pro1 -> dummy1 [dir=none] dummy1 -> dec1 [headport='w'] } [1]: 'START' [2]: 'decision 1' [3]: 'decision 2' [4]: 'decision 3' [5]: 'process 1' [6]: 'END' [7]: 'process 3' ")
Key Changes Explained:
Vertical Alignment & Straight Arrow for Process 1
- Added
{rank = same; start dec1 dec2 pro1}to ensure all these nodes sit on the same horizontal level, fixing the left offset ofprocess1. - Updated the
dec2 -> pro1edge to usetailport = 's'andheadport = 'n', forcing a straight vertical line instead of a curved one.
- Added
Vertical Alignment & Straight Arrow for Decision 3 & END
- Added
{rank = same; pro3 dec3 pro2}to alignprocess3,decision3, andENDvertically. - Changed
pro3 -> dec3to usetailport = 's'andheadport = 'n'for a straight vertical arrow.
- Added
Polyline Arrow (Optional)
- Added an invisible dummy node (
dummy1) aligned horizontally withprocess1. - Split the
pro1 -> dec1arrow into two segments: first a horizontal line to the dummy node, then a vertical/horizontal line todec1's west port, creating the desired polyline path.
- Added an invisible dummy node (
This should give you a clean, aligned flowchart with all the requested arrow behaviors!
内容的提问来源于stack exchange,提问作者alittleboy
相关产品推荐
相关产品推荐

