2014-10-06 43 views
1

因此,剛開始使用Rgraphviz並出於某種原因,它會在我真正簡單的圖上穿過線條。使用Rgraphviz無法使線條在簡單圖形中交叉

A = matrix(c(0,0,0,0,1, 
     1,0,0,0,0, 
     1,0,0,0,0, 
     1,0,0,0,0, 
     0,1,1,1,0), 
     ncol=5, byrow=TRUE) 
rownames(A)=c(1,2,3,4,5) 
colnames(A)=c(1,2,3,4,5) 

library(Rgraphviz) 
am.graph<-new("graphAM", adjMat=A, edgemode="directed") 
am.graph 
plot(am.graph, attrs = list(node = list(fillcolor = "lightblue"), 
          edge = list(arrowsize=0.5))) 

enter image description here

任何幫助表示讚賞

回答

2

RGraphiviz提供了一些佈局算法,看到了嗎?GraphvizLayouts。在您的示例中使用的默認值是「點」算法,它提供了分層佈局。其中一種替代方法「twopi」將其中一個節點作爲根節點,並將其餘節點安排在關於此根節點的一系列同心圓中。這裏可以使用第二種算法來避免圖中的交叉線。

默認情況下, 「twopi」 使用節點1作爲根:

plot(am.graph, "twopi", 
    attrs = list(node = list(fillcolor = "lightblue"), 
     edge = list(arrowsize=0.5))) 

5 node graph produces with "twopi" algorithm

然而,我們可以通過屬性(?見GraphvizAttributes)改變這種設置節點2作爲根:

plot(am.graph, "twopi", 
attrs = list(graph = list(root = 2), 
    node = list(fillcolor = "lightblue"), 
    edge = list(arrowsize=0.5))) 

這或許給出了一個佈局更接近你想什麼:

enter image description here

+0

感謝,似乎做我想要的。 – Dalupus 2014-10-15 14:33:26