Three column graph

纵然是瞬间 提交于 2019-12-05 11:32:30

Not exactly sure if this is what you want but maybe gets you some of the way there.

The idea is to first form an edge list from your data, to then create an adjacency matrix and then plot.

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" plots the graph from left to right

Above plot uses dot to give the strict structure.

EDIT

Use layout = layout.reingold.tilford to get a tree structure using igraph

E(g)$curved <- 0
plot.igraph(g, vertex.size=30, layout=layout.reingold.tilford)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!