Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three column graph

Tags:

plot

r

igraph

The result of some process is a list of paths from A to C through B, e.g.:

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

What I would like to have is a graph with three parallel columns, the first for the origin, the second for the intermediate point, and the third for the destination. In this example, the first column would have only the node 10, the second 2, 6, 24, 28 and the third 1, 9. Then, directed edges (arrows) will go from nodes in the first column to nodes in the second column, and from nodes in the second column to nodes in the third one.

Is this even possible with igraph?

Thanks in advance.

like image 612
jcredberry Avatar asked Jun 26 '14 22:06

jcredberry


People also ask

What is a three column chart?

3 column chart is a chart to arrange the contents of a document in the form of 3 columns. At the pre-school and elementary school levels, 3 columns are used in the form of ordinary tables.

How do I make a bar graph in Excel with 3 columns?

Click the "Insert" tab, then "Column" from the Charts group and "Cluster Column" from the drop-down menu. The Cluster Column option is the left-most option of each of the column types, such as 2-D, 3-D or Cylinder. The cluster column chart is automatically created by Excel on the same page as your data.

What is a 3 chart?

Three-dimensional charts provide a visually effective display that is suitable for presentations. Three-dimensional column, bar, line, and area charts plot data by using three axes. Three-dimensional pie charts have a three-dimensional visual effect.

What is a column graph in Excel?

What is a Column Chart? A column chart is a graph that shows vertical bars with the axis values for the bars displayed on the left side of the graph. It is a graphical object used to represent the data in your Excel spreadsheet. You can use a column chart when: You want to compare values across categories.


1 Answers

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

enter image description here

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)
like image 56
user20650 Avatar answered Oct 06 '22 11:10

user20650