igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Creation of Directed Graph


From: Lorenzo Isella
Subject: [igraph] Creation of Directed Graph
Date: Wed, 4 Jan 2017 16:18:00 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

Dear All,
Please have a look at the snippet at the end of the email.
I explain in some detail what I need and why I am struggling.
I need to generate a *directed* graph starting from data like


UK  FR
BE  UK
UK  FR
FR  UK

where each line indicates the movement of one agent from the country
on the left to the one on the right.

In the example before, 2 agents left the United Kingdom (UK) for
France (FR), one left Belgium (BE) for the UK, and another one left France for 
the UK.
Starting from that, there are 2 things I am after:
1) I would like to generate a directed network in
which the weight of each edge is the net flux of agents.
E.g. in the example above, the due to the agent movements, I would
have an edge from UK to FR with weight 1 (2 agents left the UK for FR
and 1 left FR for the UK). I also would like to have the weight of
each node as the total influx of agents (which could be negative,
e.g. in the case of BE above 1 agent leaves BE and no one gets there)
2) Could I actually have 2 edges between different countries (which
are nodes)? For instance, have one edge with weight 2 from UK to FR
and one with weight 1 from FR to UK.

A larger numerical example is given below, but the idea is the same.
I try to get the edge weight based on their multiplicity, but
obviously I am doing something wrong.
Any help is appreciated.
Cheers

Lorenzo






############################################################################

tab<-structure(c("NZ", "AU", "RU", "AU", "FR", "AU", "AR", "AU", "UY",
"IN", "US", "FR", "FR", "RU", "ES", "BE", "FR", "ES", "FR", "US",
"DE", "CA", "PL", "IT", "FR", "AU", "DE", "JP", "SE", "PL", "FR",
"ES", "NL", "IE", "HU", "BR", "CH", "NL", "JP", "HU", "CZ", "ES",
"IN", "IL", "AU", "CH", "PL", "FR", "PL", "FR", "HU", "ES", "IT",
"UK", "FR", "SE", "DE", "FR", "DE", "ES", "NL", "UK", "ES", "CH",
"UK", "DE", "FR", "UK", "US", "DE", "AU", "FR", "IT", "IT", "US",
"JP", "ES", "SE", "ES", "AR", "HU", "AT", "US", "IN", "AU", "NZ",
"MX", "AU", "CA", "PL", "IN", "UK", "CA", "FR", "BE", "IN", "ES",
"PL", "IE", "BE", "UK", "IT", "JP", "US", "ES", "FR", "EL", "IE",
"UK", "NL", "SI", "DE", "DE", "IT", "EG", "ES", "IT", "UA", "IT",
"AT", "ES", "IT", "ES", "ES", "PL", "FR", "NL", "IE", "US", "IT",
"HU", "CA", "DE", "DE", "CL", "PT", "NL", "PL", "PL", "IT", "PL",
"CA", "PL", "FR", "AR", "NL", "ES", "CY", "TN", "DE", "ES", "DE",
"NL", "ES", "DE", "ES", "TR", "RO", "HU", "ES", "KH", "ES", "FR",
"UK", "IT", "CH", "FR", "FR", "US", "IT", "SI", "ES", "DE", "NZ",
"TR", "FR", "SE", "IN", "FR", "FR", "BE", "BE", "US", "IT", "IT",
"IT", "FI", "DE", "UK", "IL", "IS", "FR", "FI", "IN", "FI", "SK",
"DE", "ES", "UK", "DK", "FR", "FR", "DE", "NL", "ES", "ES", "SY",
"FR", "DE", "JP", "FR", "ES", "US", "ES", "SE", "US", "ES", "CY",
"SE", "MX", "IT", "NL", "CA", "BE", "IL", "IE", "UK", "FR", "PT",
"ES", "DE", "SE", "IT", "HU", "IT", "PT", "NL", "AT", "ES", "DE",
"US", "CH", "NL", "DE", "IN", "RU", "NL", "FR", "NL", "ES", "US",
"SE", "FR", "FR", "IL", "US", "DE", "US", "IT", "FR", "DE", "IE",
"AU", "SE", "JP", "FR", "IT", "IT", "AR", "FR", "ES", "HU", "SK",
"IT", "BE", "UK", "DE", "FR", "UK", "UK", "UK", "CH", "IE", "IT",
"FI", "DE", "FR", "FR", "RU", "ES", "BE", "FR", "FR", "DE", "UK",
"UK", "DK", "UK", "FR", "DE", "SE", "AT", "DE", "UK", "SE", "BE",
"IT", "NO", "CH", "HU", "ES", "FR", "UK", "UK", "FR", "UK", "UK",
"CH", "IL", "UK", "UK", "DE", "SE", "UK", "FR", "PT", "UK", "FR",
"SE", "UK", "UK", "ES", "UK", "SE", "UK", "NL", "DE", "UK", "DE",
"ES", "DK", "CH", "ES", "FR", "UK", "UK", "UK", "ES", "IT", "FR",
"UK", "UK", "UK", "UK", "BE", "FR", "BE", "UK", "UK", "ES", "NO",
"ES", "FR", "UK", "UK", "UK", "ES", "UK", "UK", "CH", "IE", "UK",
"DE", "UK", "NL", "UK", "UK", "CZ", "SE", "UK", "UK", "DE", "DK",
"UK", "CH", "ES", "IL", "UK", "CH", "FI", "UK", "FR", "SE", "UK",
"DE", "ES", "FR", "UK", "DE", "UK", "DE", "FR", "UK", "CH", "UK",
"FI", "FR", "FR", "UK", "IT", "PT", "CH", "ES", "CH", "NO", "CH",
"NL", "UK", "CH", "UK", "CH", "CH", "EL", "CH", "UK", "UK", "UK",
"UK", "UK", "FR", "UK", "CH", "DE", "UK", "IE", "UK", "FR", "UK",
"DK", "UK", "ES", "UK", "FR", "UK", "UK", "SI", "ES", "UK", "SE",
"UK", "CH", "DE", "CH", "ES", "UK", "CH", "PT", "FR", "DE", "UK",
"CH", "UK", "CH", "UK", "UK", "UK", "UK", "CH", "UK", "DE", "DE",
"FR", "UK", "UK", "ES", "ES", "UK", "DE", "CZ", "NL", "UK", "CH",
"IE", "UK", "UK", "DE", "UK", "UK", "UK", "UK", "UK", "ES", "CA",
"ES", "UK", "ES", "DE", "SE", "CH", "UK", "ES", "FR", "UK", "IE",
"UK", "UK", "CH", "IT", "UK", "FR", "NL", "NO", "AT", "ES", "UK",
"UK", "CH", "FR", "UK", "DE", "NL", "ES", "DK", "UK", "UK", "SE",
"DE", "DE", "FR", "FR", "CH", "UK", "NL", "ES", "UK", "UK", "UK",
"UK", "UK", "UK", "FR", "FR", "UK", "SI", "ES", "DK", "DE", "NL",
"UK", "UK"), .Dim = c(275L, 2L), .Dimnames = list(NULL, c("home",
"host")))

g <- graph.data.frame(tab, dir=T)

E(g)$weight <- count.multiple(g)

g <- simplify(g)

l <- layout.fruchterman.reingold(g)
l <- layout.norm(l, -1,1, -1,1)

pdf("mc-network.pdf")
plot(g, layout=l,
      vertex.label.dist=0.5,   vertex.color="#ff000033",
      vertex.frame.color="#ff000033", edge.color="#55555533"
      vertex.size=4,
edge.arrow.size=rep(0.4, ecount(g)) )

 dev.off()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]