修复igraph中的节点

时间:2015-09-30 18:58:11

标签: r igraph

我有一个有向图,其中有一个开始和结束节点,它们被定义为没有节点离开结束且没有节点进入开始。在我的图表中,我想修复图形顶部的节点开始和底部的结束,中间节点保持在两者之间。我怎样才能做到这一点? enter image description here

> final_data_graph
             (conversion) (start)      alpha       beta        delta     epsilon        eta       gamma       iota       kappa     lambda           mi      theta
(conversion)   0.00000000       0 0.00000000 0.00000000 0.000000e+00 0.000000000 0.00000000 0.000000000 0.00000000 0.000000000 0.00000000 0.000000e+00 0.00000000
(start)        0.00000000       0 0.03771482 0.14413063 8.571551e-05 0.006128659 0.18025972 0.013071615 0.47426392 0.002914327 0.03891484 4.285776e-05 0.10118716
alpha          0.18078800       0 0.58092440 0.03215991 1.049263e-04 0.017732543 0.03667174 0.002675620 0.06395257 0.005666020 0.03242222 0.000000e+00 0.03840302
beta           0.09504413       0 0.08766124 0.35022064 8.486083e-05 0.009164969 0.24753904 0.004327902 0.12075696 0.004752206 0.02274270 0.000000e+00 0.04760692
delta          0.53333333       0 0.00000000 0.00000000 0.000000e+00 0.066666667 0.00000000 0.000000000 0.26666667 0.066666667 0.00000000 0.000000e+00 0.06666667
epsilon        0.38628763       0 0.13991081 0.04347826 0.000000e+00 0.105351171 0.08193980 0.005574136 0.10200669 0.007246377 0.05128205 0.000000e+00 0.05351171
eta            0.42928641       0 0.11002583 0.09969325 0.000000e+00 0.023167582 0.19058767 0.002421698 0.07402325 0.008072328 0.01840491 0.000000e+00 0.03535680
gamma          0.28192371       0 0.14427861 0.05804312 0.000000e+00 0.021558872 0.08291874 0.066334992 0.15754561 0.018242123 0.05306799 0.000000e+00 0.09950249
iota           0.23902022       0 0.06370199 0.04091585 1.102111e-04 0.009202623 0.03240205 0.001790930 0.53868408 0.004573759 0.02669863 5.510553e-05 0.03160302
kappa          0.43064985       0 0.06886518 0.03685742 9.699321e-04 0.018428710 0.06498545 0.002909796 0.09602328 0.128031038 0.05431620 0.000000e+00 0.08244423
lambda         0.34914361       0 0.08695652 0.02561850 5.855658e-04 0.020348412 0.02547211 0.002488655 0.07539160 0.034401991 0.31620553 0.000000e+00 0.04977309
mi             0.00000000       0 0.25000000 0.00000000 0.000000e+00 0.000000000 0.00000000 0.000000000 0.50000000 0.000000000 0.00000000 2.500000e-01 0.00000000
theta          0.13940821       0 0.17562196 0.07949360 1.472104e-04 0.025320183 0.07198587 0.004269101 0.13513911 0.019431768 0.20491683 0.000000e+00 0.12939791
zeta           0.09929633       0 0.15871775 0.07427678 0.000000e+00 0.039874902 0.07974980 0.001563722 0.23612197 0.007036747 0.08444097 0.000000e+00 0.07271306
                    zeta
(conversion) 0.000000000
(start)      0.001285733
alpha        0.008499029
beta         0.010098439
delta        0.000000000
epsilon      0.023411371
eta          0.008960284
gamma        0.016583748
iota         0.011241528
kappa        0.015518914
lambda       0.013614405
mi           0.000000000
theta        0.014868247
zeta         0.146207975

ig <- graph.adjacency(final_data_graph, mode="directed", weighted=TRUE)

plot(ig,edge.label=round(E(ig)$weight,3),edge.width=.01,edge.arrow.size=.05,layout=layout.reingold.tilford(ig, root=which(V(ig)$name=='(start)')),vertex.color="white")

1 个答案:

答案 0 :(得分:3)

我假设您要绘制图形,顶部的起始节点和底部的结尾。如果是,您可以使用layout.reingold.tilford,例如:

library(igraph)

# example graph
g <- graph.empty(directed = T)
g <- g + vertices(c('D','A','E','F','C','B'))
g <- g + edge('A','B')
g <- g + edge('A','C')
g <- g + edge('B','E')
g <- g + edge('B','D')
g <- g + edge('C','D')
g <- g + edge('D','F')
g <- g + edge('E','F')

# create the layout specifying the root node (i.e. start)
ly <- layout.reingold.tilford(g, root=which(V(g)$name=='A'),flip.y=T)
# let's plot
plot.igraph(g,layout=ly)

enter image description here