2014-06-26 110 views
5

一些過程的結果是通過乙從A到C的路徑列表,例如:三個柱形圖

which.effect(A1,A2,10,1,1) 
[[1]] 
[1] 10 2 1 

[[2]] 
[1] 10 28 1 

[[3]] 
[1] 10 6 9 

[[4]] 
[1] 10 24 9 

[[5]] 
[1] 10 28 9 

我想有是具有三個平行的列的曲線圖,所述第一對起點,第二個爲中間點,第三個爲目的地。在本例中,第一列將只有節點10,第二個2, 6, 24, 28和第三個1, 9。然後,有向邊(箭頭)將從第一列中的節點到第二列中的節點,並且從第二列中的節點到第三列中的節點。

這是甚至可能與igraph

在此先感謝。

+0

得到一個樹形結構,我想我誤刪@的Gabor-csardi答案。有沒有辦法恢復它? – jcredberry

回答

6

不完全確定這是你想要的,但也許會讓你有一些方法。

這個想法是首先從你的數據形成一個邊緣列表,然後創建一個鄰接矩陣然後繪圖。

library(igraph) 
library(Rgraphviz) 

# your data 
lst <- list(c(10,2,1), c(10,28,1), c(10,6,9), c(10,24,9), c(10,28,9)) 

# create edge list (from in first column/to in the second) 
d <- do.call(rbind, lst) 
edges <- rbind(d[,1:2], d[,2:3]) 

# get adjacency matrix 
g <- graph.data.frame(edges, directed=TRUE) 
adj <- as.matrix(get.adjacency(g)) 

# convert to a graph object and plot 
g2 <- new("graphAM", adjMat=adj, edgemode="directed") 
plot(g2, attrs = list(graph = list(rankdir="LR"), 
          node = list(fillcolor = "lightblue"))) 

rankdir="LR"曲線圖從左至右

enter image description here

以上小區採用dot給予嚴格的結構。

編輯

使用layout = layout.reingold.tilford使用igraph

E(g)$curved <- 0 
plot.igraph(g, vertex.size=30, layout=layout.reingold.tilford)