如何修改此图的布局?

How to modify the layout of this graph?

我已经创建了一个图形对象,但我想自己选择布局。我想到的布局是第一个节点 Fs 放在最左边,然后 DCs 然后 CC 最后 Ws 在最远的地方正确的。我们也可以将 DCCC 放在一起。 您可以通过以下代码生成图形:

graph_from_literal(F1--+DC1, F1--+DC2, F1--+DC3, F1--+CC, F1--+W1, F1--+W2, F1--+W3,
                   F2--+DC1, F2--+DC2, F2--+DC3, F2--+CC, F2--+W1, F2--+W2, F2--+W3, 
                   DC1--+CC, DC1--+W1, DC1--+W2, DC1--+W3, 
                   DC2--+CC, DC2--+W1, DC2--+W2, DC2--+W3, 
                   DC3--+CC, DC3--+W1, DC3--+W2, DC3--+W3, 
                   CC--+W1, CC--+W2, CC--+W3)

我在 plot 函数中尝试了 layout 参数,但结果不是我想要的。如果能提前提供帮助,我将不胜感激。

如果你想自定义你的分层图,我们可以试试

# assign x-coordiates of vertices in terms of their names by following the desired order, i.e., from left to right
x_lo <- match(gsub("\d", "", names(V(g))), c("F", "DC", "CC", "W"))

# assign y-coordinates uniformly within the range [-5,5] (grouped by `x_lo`), or we can also use random values if you like
y_lo <- ave(x_lo, x_lo, FUN = function(v) seq(-5, 5, length.out = length(v)))

plot(g, layout = cbind(x_lo, y_lo))

给出


另一个选项可能是使用 layout_with_sugiyama

plot(g, layout = -layout_with_sugiyama(g)$layout[,2:1])

幸运的是我们会得到