Network with three-dimensional edgelist?

120 views Asked by At

I have data which provides information on flows by actor c, broken down by inputs originating from source s, to partner p.

Network data normally has only one information: Data / Information flows from A->B, B->C etc.

However, my data shows which flows from A->B then goes to C, and which from A->B goes to D.

The data is structured as a three-column edgelist.

source <- c("A", "D", "B", "B")
country <- c("B", "B", "A", "A")
partner <- c("C", "C", "C", "D")
value <- c("5", "0", "2", "4")

df <- data.frame(source, country, partner, value)

df

I kinda dont see how it would be possible to use this as network data - however, if anyone got an idea on how to use that way more fine-grained network that be amazing ((:

best,

moritz

2

There are 2 answers

1
zx8754 On

Maybe like this:

library(igraph)

g <- graph_from_data_frame(
  rbind(
    setNames(df[, c(1, 2, 4)], c("from", "to", "value")),
    setNames(df[, c(1, 3, 4)], c("from", "to", "value"))
  )
)

plot(g)

enter image description here

2
ThomasIsCoding On

I am not sure if the code below is what you want

library(igraph)
v <- c(3,1)
g <- Reduce(union,lapply(v, function(k) graph_from_data_frame(df[-k])))

such that plot(g) gives

enter image description here