三列图

jcr*_*rry 5 plot r igraph

某个过程的结果是从A到C到B的路径列表,例如:

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
Run Code Online (Sandbox Code Playgroud)

我想要的是一个包含三个平行列的图形,第一列为原点,第二列为中间点,第三列为目标.在此示例中,第一列仅具有节点10,第二列2, 6, 24, 28和第三列1, 9.然后,有向边(箭头)将从第一列中的节点转到第二列中的节点,并从第二列中的节点转到第三列中的节点.

这有可能igraph吗?

提前致谢.

use*_*650 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")))
Run Code Online (Sandbox Code Playgroud)

rankdir="LR" 从左到右绘制图形

在此输入图像描述

上图用于dot给出严格的结构.

编辑

使用layout = layout.reingold.tilford使用获取树型结构igraph

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